s4:lib: Make sure we close fd's in error path
authorAndreas Schneider <asn@samba.org>
Mon, 9 Dec 2019 08:58:42 +0000 (09:58 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 10 Dec 2019 00:30:29 +0000 (00:30 +0000)
Found by covscan.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Richard Sharpe <realrichardsharpe@gmail.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/lib/policy/gp_filesys.c

index 69fb143c68703d2774d2d605978734974b641f55..5a300f134fea57e4fbe7150911a53eb6989c695e 100644 (file)
@@ -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);