From: Andreas Schneider Date: Mon, 9 Dec 2019 08:58:42 +0000 (+0100) Subject: s4:lib: Make sure we close fd's in error path X-Git-Tag: ldb-2.1.0~372 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c2e55821bc5db1a33ecd2f7550a75ebdbe7613f9;p=thirdparty%2Fsamba.git s4:lib: Make sure we close fd's in error path Found by covscan. Signed-off-by: Andreas Schneider Reviewed-by: Richard Sharpe Reviewed-by: Andrew Bartlett --- diff --git a/source4/lib/policy/gp_filesys.c b/source4/lib/policy/gp_filesys.c index 69fb143c687..5a300f134fe 100644 --- a/source4/lib/policy/gp_filesys.c +++ b/source4/lib/policy/gp_filesys.c @@ -421,7 +421,7 @@ static NTSTATUS push_recursive (struct gp_context *gp_ctx, const char *local_pat struct dirent *dirent; char *entry_local_path = NULL; char *entry_remote_path = NULL; - int local_fd, remote_fd; + int local_fd = -1, remote_fd = -1; int buf[1024]; int nread, total_read; struct stat s; @@ -494,7 +494,9 @@ static NTSTATUS push_recursive (struct gp_context *gp_ctx, const char *local_pat } close(local_fd); + local_fd = -1; smbcli_close(gp_ctx->cli->tree, remote_fd); + remote_fd = -1; } TALLOC_FREE(entry_local_path); TALLOC_FREE(entry_remote_path); @@ -502,6 +504,12 @@ static NTSTATUS push_recursive (struct gp_context *gp_ctx, const char *local_pat status = NT_STATUS_OK; done: + if (local_fd != -1) { + close(local_fd); + } + if (remote_fd != -1) { + smbcli_close(gp_ctx->cli->tree, remote_fd); + } talloc_free(entry_local_path); talloc_free(entry_remote_path);