From 406dceaa77abcd72fc05b1e1f476263ae82fd83d Mon Sep 17 00:00:00 2001 From: linqiheng Date: Thu, 12 Jan 2023 12:10:28 +0000 Subject: [PATCH] hmdfs: fix client readdir dentry file leak Signed-off-by: linqiheng --- fs/hmdfs/comm/socket_adapter.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/fs/hmdfs/comm/socket_adapter.c b/fs/hmdfs/comm/socket_adapter.c index eff3d3e1c044..913d667f0f73 100644 --- a/fs/hmdfs/comm/socket_adapter.c +++ b/fs/hmdfs/comm/socket_adapter.c @@ -409,18 +409,23 @@ int hmdfs_sendmessage_request(struct hmdfs_peer *con, struct hmdfs_head_cmd *head = NULL; bool dec = false; - if (!hmdfs_is_node_online(con)) - return -EAGAIN; + if (!hmdfs_is_node_online(con)) { + ret = -EAGAIN; + goto free_filp; + } if (timeout == TIMEOUT_UNINIT) { hmdfs_err_ratelimited("send msg %d with uninitialized timeout", sm->operations.command); - return -EINVAL; + ret = -EINVAL; + goto free_filp; } head = kzalloc(sizeof(struct hmdfs_head_cmd), GFP_KERNEL); - if (!head) - return -ENOMEM; + if (!head) { + ret = -ENOMEM; + goto free_filp; + } sm->out_buf = NULL; head->magic = HMDFS_MSG_MAGIC; @@ -504,6 +509,11 @@ int hmdfs_sendmessage_request(struct hmdfs_peer *con, hmdfs_dec_msg_idr_process(con); kfree(head); return ret; + +free_filp: + if (sm->local_filp) + fput(sm->local_filp); + return ret; } static int hmdfs_send_slice(struct hmdfs_peer *con, struct hmdfs_head_cmd *cmd, -- Gitee