summaryrefslogtreecommitdiff
path: root/source4/client
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2005-11-02 03:08:52 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:45:40 -0500
commit827cbb480c6de7471554c97cb4cef13e5db7b2b3 (patch)
tree1d807adc079a4e0cfe860d08e0ae63a0a139822f /source4/client
parent6dfb09c5a5b85fa7fce85b518cc2a6ee008b0bbd (diff)
downloadsamba-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)
Diffstat (limited to 'source4/client')
-rw-r--r--source4/client/client.c33
1 files changed, 17 insertions, 16 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;
}