svn commit: samba r11466 - in branches/SAMBA_4_0/source: client
libcli/raw
abartlet at samba.org
abartlet at samba.org
Wed Nov 2 03:08:53 GMT 2005
Author: abartlet
Date: 2005-11-02 03:08:52 +0000 (Wed, 02 Nov 2005)
New Revision: 11466
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=11466
Log:
Clear up some memory leaks in smbclient.
Andrew Bartlett
Modified:
branches/SAMBA_4_0/source/client/client.c
branches/SAMBA_4_0/source/libcli/raw/clitree.c
Changeset:
Modified: branches/SAMBA_4_0/source/client/client.c
===================================================================
--- branches/SAMBA_4_0/source/client/client.c 2005-11-02 02:35:50 UTC (rev 11465)
+++ branches/SAMBA_4_0/source/client/client.c 2005-11-02 03:08:52 UTC (rev 11466)
@@ -77,10 +77,7 @@
/* 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 @@
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 @@
/*****************************************************
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 @@
{
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 @@
process_stdin();
}
- talloc_free(cli);
+ talloc_free(mem_ctx);
return rc;
}
Modified: branches/SAMBA_4_0/source/libcli/raw/clitree.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/raw/clitree.c 2005-11-02 02:35:50 UTC (rev 11465)
+++ branches/SAMBA_4_0/source/libcli/raw/clitree.c 2005-11-02 03:08:52 UTC (rev 11466)
@@ -172,10 +172,14 @@
{
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 @@
if (NT_STATUS_IS_OK(status)) {
*ret_tree = io.out.tree;
}
-
+ talloc_free(tmp_ctx);
return status;
}
More information about the samba-cvs
mailing list