summaryrefslogtreecommitdiff
path: root/source4/libcli
diff options
context:
space:
mode:
Diffstat (limited to 'source4/libcli')
-rw-r--r--source4/libcli/cliconnect.c15
-rw-r--r--source4/libcli/raw/clisession.c14
-rw-r--r--source4/libcli/raw/clitransport.c3
-rw-r--r--source4/libcli/raw/clitree.c22
4 files changed, 15 insertions, 39 deletions
diff --git a/source4/libcli/cliconnect.c b/source4/libcli/cliconnect.c
index f772070305..aa6aec4a1e 100644
--- a/source4/libcli/cliconnect.c
+++ b/source4/libcli/cliconnect.c
@@ -36,8 +36,8 @@ BOOL smbcli_socket_connect(struct smbcli_state *cli, const char *server)
}
cli->transport = smbcli_transport_init(sock);
+ talloc_free(sock);
if (!cli->transport) {
- talloc_free(sock);
return False;
}
@@ -60,9 +60,9 @@ NTSTATUS smbcli_negprot(struct smbcli_state *cli)
/* wrapper around smb_raw_session_setup() */
NTSTATUS smbcli_session_setup(struct smbcli_state *cli,
- const char *user,
- const char *password,
- const char *domain)
+ const char *user,
+ const char *password,
+ const char *domain)
{
union smb_sesssetup setup;
NTSTATUS status;
@@ -70,6 +70,7 @@ NTSTATUS smbcli_session_setup(struct smbcli_state *cli,
cli->session = smbcli_session_init(cli->transport);
if (!cli->session) return NT_STATUS_UNSUCCESSFUL;
+ talloc_free(cli->transport);
mem_ctx = talloc_init("smbcli_session_setup");
if (!mem_ctx) return NT_STATUS_NO_MEMORY;
@@ -110,6 +111,7 @@ NTSTATUS smbcli_send_tconX(struct smbcli_state *cli, const char *sharename,
NTSTATUS status;
cli->tree = smbcli_tree_init(cli->session);
+ talloc_free(cli->session);
if (!cli->tree) return NT_STATUS_UNSUCCESSFUL;
mem_ctx = talloc_init("tcon");
@@ -183,7 +185,8 @@ NTSTATUS smbcli_full_connection(struct smbcli_state **ret_cli,
(*ret_cli) = smbcli_state_init();
- (*ret_cli)->tree = tree;
+ (*ret_cli)->tree = talloc_reference(*ret_cli, tree);
+ talloc_free(tree);
(*ret_cli)->session = tree->session;
(*ret_cli)->transport = tree->session->transport;
@@ -221,7 +224,5 @@ struct smbcli_state *smbcli_state_init(void)
****************************************************************************/
void smbcli_shutdown(struct smbcli_state *cli)
{
- if (!cli) return;
- talloc_free(cli->tree);
talloc_free(cli);
}
diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c
index 0c6c80d94c..431d225021 100644
--- a/source4/libcli/raw/clisession.c
+++ b/source4/libcli/raw/clisession.c
@@ -27,16 +27,6 @@
} while (0)
-/*
- destroy a smbcli_session
-*/
-static int session_destroy(void *ptr)
-{
- struct smbcli_session *session = ptr;
- talloc_free(session->transport);
- return 0;
-}
-
/****************************************************************************
Initialize the session context
****************************************************************************/
@@ -50,12 +40,10 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport)
}
ZERO_STRUCTP(session);
- session->transport = transport;
+ session->transport = talloc_reference(session, transport);
session->pid = (uint16_t)getpid();
session->vuid = UID_FIELD_INVALID;
- talloc_set_destructor(session, session_destroy);
-
return session;
}
diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c
index eb1d3631ee..f06f2c57ff 100644
--- a/source4/libcli/raw/clitransport.c
+++ b/source4/libcli/raw/clitransport.c
@@ -52,7 +52,6 @@ static int transport_destructor(void *ptr)
event_remove_fd(transport->event.ctx, transport->event.fde);
event_remove_timed(transport->event.ctx, transport->event.te);
event_context_destroy(transport->event.ctx);
- talloc_free(transport->socket);
return 0;
}
@@ -75,7 +74,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock)
return NULL;
}
- transport->socket = sock;
+ transport->socket = talloc_reference(transport, sock);
transport->negotiate.protocol = PROTOCOL_NT1;
transport->options.use_spnego = lp_use_spnego();
transport->negotiate.max_xmit = ~0;
diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c
index e0072a31b1..f19cbf8e28 100644
--- a/source4/libcli/raw/clitree.c
+++ b/source4/libcli/raw/clitree.c
@@ -26,16 +26,6 @@
if (!req) return NULL; \
} while (0)
-/*
- destroy a smbcli_tree
-*/
-static int tree_destructor(void *ptr)
-{
- struct smbcli_tree *tree = ptr;
- talloc_free(tree->session);
- return 0;
-}
-
/****************************************************************************
Initialize the tree context
****************************************************************************/
@@ -49,8 +39,7 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session)
}
ZERO_STRUCTP(tree);
- tree->session = session;
- talloc_set_destructor(tree, tree_destructor);
+ tree->session = talloc_reference(tree, session);
return tree;
}
@@ -188,17 +177,16 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree,
return NT_STATUS_NO_MEMORY;
}
- talloc_set_name_const(sock, "smbcli_tree_full_connection");
-
/* open a TCP socket to the server */
if (!smbcli_sock_connect_byname(sock, dest_host, port)) {
+ talloc_free(sock);
DEBUG(2,("Failed to establish socket connection - %s\n", strerror(errno)));
return NT_STATUS_UNSUCCESSFUL;
}
transport = smbcli_transport_init(sock);
+ talloc_free(sock);
if (!transport) {
- talloc_free(sock);
return NT_STATUS_NO_MEMORY;
}
@@ -220,8 +208,8 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree,
}
session = smbcli_session_init(transport);
+ talloc_free(transport);
if (!session) {
- talloc_free(transport);
return NT_STATUS_NO_MEMORY;
}
@@ -255,8 +243,8 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree,
session->vuid = setup.generic.out.vuid;
tree = smbcli_tree_init(session);
+ talloc_free(session);
if (!tree) {
- talloc_free(session);
talloc_free(mem_ctx);
return NT_STATUS_NO_MEMORY;
}