diff options
author | Andrew Bartlett <abartlet@samba.org> | 2005-11-02 03:08:52 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:45:40 -0500 |
commit | 827cbb480c6de7471554c97cb4cef13e5db7b2b3 (patch) | |
tree | 1d807adc079a4e0cfe860d08e0ae63a0a139822f | |
parent | 6dfb09c5a5b85fa7fce85b518cc2a6ee008b0bbd (diff) | |
download | samba-827cbb480c6de7471554c97cb4cef13e5db7b2b3.tar.gz samba-827cbb480c6de7471554c97cb4cef13e5db7b2b3.tar.bz2 samba-827cbb480c6de7471554c97cb4cef13e5db7b2b3.zip |
r11466: Clear up some memory leaks in smbclient.
Andrew Bartlett
(This used to be commit 6535959fd7dfddd6bafb77a266ec3a641025f880)
-rw-r--r-- | source4/client/client.c | 33 | ||||
-rw-r--r-- | source4/libcli/raw/clitree.c | 8 |
2 files changed, 23 insertions, 18 deletions
diff --git a/source4/client/client.c b/source4/client/client.c index 034b6786a0..a8d22e75b7 100644 --- a/source4/client/client.c +++ b/source4/client/client.c @@ -77,9 +77,6 @@ static uint_t put_total_time_ms = 0; /* totals globals */ static double dir_total; -/* some forward declarations */ -static struct smbcli_state *do_connect(const char *server, const char *share, struct cli_credentials *cred); - /******************************************************************* Reduce a file name, removing .. elements. @@ -2919,14 +2916,6 @@ static int process_command_string(char *cmd) const char *ptr; int rc = 0; - /* establish the connection if not already */ - - if (!cli) { - cli = do_connect(desthost, service, cmdline_credentials); - if (!cli) - return 0; - } - while (cmd[0] != '\0') { char *p; fstring tok; @@ -3208,23 +3197,30 @@ static void process_stdin(void) /***************************************************** return a connection to a server *******************************************************/ -static struct smbcli_state *do_connect(const char *server, const char *share, struct cli_credentials *cred) +static struct smbcli_state *do_connect(TALLOC_CTX *mem_ctx, + const char *server, const char *share, struct cli_credentials *cred) { struct smbcli_state *c; NTSTATUS status; + TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); + if (!tmp_ctx) { + return NULL; + } if (strncmp(share, "\\\\", 2) == 0 || strncmp(share, "//", 2) == 0) { - smbcli_parse_unc(share, NULL, &server, &share); + smbcli_parse_unc(share, tmp_ctx, &server, &share); } - status = smbcli_full_connection(NULL, &c, server, + status = smbcli_full_connection(mem_ctx, &c, server, share, NULL, cred, NULL); if (!NT_STATUS_IS_OK(status)) { d_printf("Connection to \\\\%s\\%s failed - %s\n", server, share, nt_errstr(status)); + talloc_free(tmp_ctx); return NULL; } + talloc_free(tmp_ctx); return c; } @@ -3237,7 +3233,12 @@ static int process(char *base_directory) { int rc = 0; - cli = do_connect(desthost, service, cmdline_credentials); + TALLOC_CTX *mem_ctx = talloc_new(NULL); + if (!mem_ctx) { + return 1; + } + + cli = do_connect(mem_ctx, desthost, service, cmdline_credentials); if (!cli) { return 1; } @@ -3250,7 +3251,7 @@ static int process(char *base_directory) process_stdin(); } - talloc_free(cli); + talloc_free(mem_ctx); return rc; } diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 990552d64f..96d36c569c 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -172,10 +172,14 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, { struct smb_composite_connect io; NTSTATUS status; + TALLOC_CTX *tmp_ctx = talloc_new(parent_ctx); + if (!tmp_ctx) { + return NT_STATUS_NO_MEMORY; + } io.in.dest_host = dest_host; io.in.port = port; - io.in.called_name = strupper_talloc(parent_ctx, dest_host); + io.in.called_name = strupper_talloc(tmp_ctx, dest_host); io.in.service = service; io.in.service_type = service_type; io.in.credentials = credentials; @@ -186,6 +190,6 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, if (NT_STATUS_IS_OK(status)) { *ret_tree = io.out.tree; } - + talloc_free(tmp_ctx); return status; } |