From e6d2b6c71347f8edc6a707f3516d416ff0920760 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 20 Jun 2023 14:20:17 +0200 Subject: [PATCH] sftpserver: Avoid leaking fd and dir on allocation error CID 1513160 and CID 1513159 Thanks coverity Signed-off-by: Jakub Jelen Reviewed-by: Sahana Prasad --- src/sftpserver.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sftpserver.c b/src/sftpserver.c index 57983f57..ddeffce8 100644 --- a/src/sftpserver.c +++ b/src/sftpserver.c @@ -905,6 +905,7 @@ process_open(sftp_client_message client_msg) h = calloc(1, sizeof (struct sftp_handle)); if (h == NULL) { + close(fd); SSH_LOG(SSH_LOG_PROTOCOL, "failed to allocate a new handle"); sftp_reply_status(client_msg, SSH_FX_FAILURE, "Failed to allocate new handle"); @@ -1091,6 +1092,7 @@ process_opendir(sftp_client_message client_msg) h = calloc(1, sizeof (struct sftp_handle)); if (h == NULL) { + closedir(dir); SSH_LOG(SSH_LOG_PROTOCOL, "failed to allocate a new handle"); sftp_reply_status(client_msg, SSH_FX_FAILURE, "Failed to allocate new handle");