1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

r11466: Clear up some memory leaks in smbclient.

Andrew Bartlett
This commit is contained in:
Andrew Bartlett 2005-11-02 03:08:52 +00:00 committed by Gerald (Jerry) Carter
parent 3af867a3f4
commit 6535959fd7
2 changed files with 23 additions and 18 deletions

View File

@ -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;
}

View File

@ -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;
}