diff options
author | Andreas Schneider <asn@samba.org> | 2013-02-20 10:22:00 +0100 |
---|---|---|
committer | Alexander Bokovoy <ab@samba.org> | 2013-02-22 16:36:14 +0100 |
commit | aa6cc31ef9b1789b3e81222204f30ba01d69803a (patch) | |
tree | c3d94bdff29035457f59fcd53d7529fbf414be5d /source4 | |
parent | 82e9ff81cf6a9945cad799ae35279e16837b8033 (diff) | |
download | samba-aa6cc31ef9b1789b3e81222204f30ba01d69803a.tar.gz samba-aa6cc31ef9b1789b3e81222204f30ba01d69803a.tar.bz2 samba-aa6cc31ef9b1789b3e81222204f30ba01d69803a.zip |
s4-policy: Fix memory leaks in push_recursive().
Reviewed-by: Alexander Bokovoy <ab@samba.org>
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/policy/gp_filesys.c | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/source4/lib/policy/gp_filesys.c b/source4/lib/policy/gp_filesys.c index 17894a7072..9f60d2f98d 100644 --- a/source4/lib/policy/gp_filesys.c +++ b/source4/lib/policy/gp_filesys.c @@ -392,12 +392,13 @@ static NTSTATUS push_recursive (struct gp_context *gp_ctx, const char *local_pat { DIR *dir; struct dirent *dirent; - char *entry_local_path; - char *entry_remote_path; + char *entry_local_path = NULL; + char *entry_remote_path = NULL; int local_fd, remote_fd; int buf[1024]; int nread, total_read; struct stat s; + NTSTATUS status; dir = opendir(local_path); while ((dirent = readdir(dir)) != NULL) { @@ -408,14 +409,21 @@ static NTSTATUS push_recursive (struct gp_context *gp_ctx, const char *local_pat entry_local_path = talloc_asprintf(gp_ctx, "%s/%s", local_path, dirent->d_name); - NT_STATUS_HAVE_NO_MEMORY(entry_local_path); + if (entry_local_path == NULL) { + status = NT_STATUS_NO_MEMORY; + goto done; + } entry_remote_path = talloc_asprintf(gp_ctx, "%s\\%s", remote_path, dirent->d_name); - NT_STATUS_HAVE_NO_MEMORY(entry_remote_path); + if (entry_remote_path == NULL) { + status = NT_STATUS_NO_MEMORY; + goto done; + } if (stat(entry_local_path, &s) != 0) { - return NT_STATUS_UNSUCCESSFUL; + status = NT_STATUS_UNSUCCESSFUL; + goto done; } if (s.st_mode & S_IFDIR) { DEBUG(6, ("Pushing directory %s to %s on sysvol\n", @@ -433,19 +441,17 @@ static NTSTATUS push_recursive (struct gp_context *gp_ctx, const char *local_pat O_WRONLY | O_CREAT, 0); if (remote_fd < 0) { - talloc_free(entry_local_path); - talloc_free(entry_remote_path); DEBUG(0, ("Failed to create remote file: %s\n", entry_remote_path)); - return NT_STATUS_UNSUCCESSFUL; + status = NT_STATUS_UNSUCCESSFUL; + goto done; } local_fd = open(entry_local_path, O_RDONLY); if (local_fd < 0) { - talloc_free(entry_local_path); - talloc_free(entry_remote_path); DEBUG(0, ("Failed to open local file: %s\n", entry_local_path)); - return NT_STATUS_UNSUCCESSFUL; + status = NT_STATUS_UNSUCCESSFUL; + goto done; } total_read = 0; while ((nread = read(local_fd, &buf, sizeof(buf)))) { @@ -457,12 +463,18 @@ static NTSTATUS push_recursive (struct gp_context *gp_ctx, const char *local_pat close(local_fd); smbcli_close(gp_ctx->cli->tree, remote_fd); } - talloc_free(entry_local_path); - talloc_free(entry_remote_path); + TALLOC_FREE(entry_local_path); + TALLOC_FREE(entry_remote_path); } + + status = NT_STATUS_OK; +done: + talloc_free(entry_local_path); + talloc_free(entry_remote_path); + closedir(dir); - return NT_STATUS_OK; + return status; } |