The branch, v3-5-test has been updated via cf36427 s3: Remove a global variable in bugfix for bug 7665 via f9f5482 s3-libnetapi: Fix Bug #7665, memory leak in netapi connection manager. from 73a7100 s3: Fix the charset_pull routine
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-5-test - Log ----------------------------------------------------------------- commit cf364274cbae996fbe186b2c2792b212f189e26a Author: Volker Lendecke <v...@samba.org> Date: Tue Sep 21 15:41:23 2010 -0700 s3: Remove a global variable in bugfix for bug 7665 commit f9f54825238d4e30827dea897456ff8cf4e6730c Author: Günther Deschner <g...@samba.org> Date: Mon Sep 20 21:05:37 2010 -0700 s3-libnetapi: Fix Bug #7665, memory leak in netapi connection manager. Guenther (cherry picked from commit 6f47a24bc55be0ea907594a748774675a105b5e3) ----------------------------------------------------------------------- Summary of changes: source3/lib/netapi/cm.c | 98 ++++++++++++++++++++++++----------- source3/lib/netapi/netapi_private.h | 1 + 2 files changed, 69 insertions(+), 30 deletions(-) Changeset truncated at 500 lines: diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index 3a624bf..97a5968 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -25,18 +25,58 @@ /******************************************************************** ********************************************************************/ +struct client_ipc_connection { + struct client_ipc_connection *prev, *next; + struct cli_state *cli; + struct client_pipe_connection *pipe_connections; +}; + +struct client_pipe_connection { + struct client_pipe_connection *prev, *next; + struct rpc_pipe_client *pipe; +}; + +/******************************************************************** +********************************************************************/ + +static struct client_ipc_connection *ipc_cm_find( + struct libnetapi_private_ctx *priv_ctx, const char *server_name) +{ + struct client_ipc_connection *p; + + for (p = priv_ctx->ipc_connections; p; p = p->next) { + if (strequal(p->cli->desthost, server_name)) { + return p; + } + } + + return NULL; +} + +/******************************************************************** +********************************************************************/ + static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, const char *server_name, - struct cli_state **cli) + struct client_ipc_connection **pp) { + struct libnetapi_private_ctx *priv_ctx = + (struct libnetapi_private_ctx *)ctx->private_data; struct user_auth_info *auth_info = NULL; struct cli_state *cli_ipc = NULL; + struct client_ipc_connection *p; - if (!ctx || !cli || !server_name) { + if (!ctx || !pp || !server_name) { return WERR_INVALID_PARAM; } - auth_info = user_auth_info_init(NULL); + p = ipc_cm_find(priv_ctx, server_name); + if (p) { + *pp = p; + return WERR_OK; + } + + auth_info = user_auth_info_init(ctx); if (!auth_info) { return WERR_NOMEM; } @@ -78,30 +118,29 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, return WERR_CAN_NOT_COMPLETE; } - *cli = cli_ipc; + p = TALLOC_ZERO_P(ctx, struct client_ipc_connection); + if (p == NULL) { + return WERR_NOMEM; + } - return WERR_OK; -} + p->cli = cli_ipc; + DLIST_ADD(priv_ctx->ipc_connections, p); -/******************************************************************** -********************************************************************/ + *pp = p; -struct client_pipe_connection { - struct client_pipe_connection *prev, *next; - struct rpc_pipe_client *pipe; - struct cli_state *cli; -}; - -static struct client_pipe_connection *pipe_connections; + return WERR_OK; +} /******************************************************************** ********************************************************************/ WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx) { - struct client_pipe_connection *p; + struct libnetapi_private_ctx *priv_ctx = + (struct libnetapi_private_ctx *)ctx->private_data; + struct client_ipc_connection *p; - for (p = pipe_connections; p; p = p->next) { + for (p = priv_ctx->ipc_connections; p; p = p->next) { cli_shutdown(p->cli); } @@ -111,19 +150,19 @@ WERROR libnetapi_shutdown_cm(struct libnetapi_ctx *ctx) /******************************************************************** ********************************************************************/ -static NTSTATUS pipe_cm_find(struct cli_state *cli, +static NTSTATUS pipe_cm_find(struct client_ipc_connection *ipc, const struct ndr_syntax_id *interface, struct rpc_pipe_client **presult) { struct client_pipe_connection *p; - for (p = pipe_connections; p; p = p->next) { + for (p = ipc->pipe_connections; p; p = p->next) { if (!rpc_pipe_np_smb_conn(p->pipe)) { return NT_STATUS_PIPE_EMPTY; } - if (strequal(cli->desthost, p->pipe->desthost) + if (strequal(ipc->cli->desthost, p->pipe->desthost) && ndr_syntax_id_equal(&p->pipe->abstract_syntax, interface)) { *presult = p->pipe; @@ -138,7 +177,7 @@ static NTSTATUS pipe_cm_find(struct cli_state *cli, ********************************************************************/ static NTSTATUS pipe_cm_connect(TALLOC_CTX *mem_ctx, - struct cli_state *cli, + struct client_ipc_connection *ipc, const struct ndr_syntax_id *interface, struct rpc_pipe_client **presult) { @@ -150,14 +189,13 @@ static NTSTATUS pipe_cm_connect(TALLOC_CTX *mem_ctx, return NT_STATUS_NO_MEMORY; } - status = cli_rpc_pipe_open_noauth(cli, interface, &p->pipe); + status = cli_rpc_pipe_open_noauth(ipc->cli, interface, &p->pipe); if (!NT_STATUS_IS_OK(status)) { TALLOC_FREE(p); return status; } - p->cli = cli; - DLIST_ADD(pipe_connections, p); + DLIST_ADD(ipc->pipe_connections, p); *presult = p->pipe; return NT_STATUS_OK; @@ -167,15 +205,15 @@ static NTSTATUS pipe_cm_connect(TALLOC_CTX *mem_ctx, ********************************************************************/ static NTSTATUS pipe_cm_open(TALLOC_CTX *ctx, - struct cli_state *cli, + struct client_ipc_connection *ipc, const struct ndr_syntax_id *interface, struct rpc_pipe_client **presult) { - if (NT_STATUS_IS_OK(pipe_cm_find(cli, interface, presult))) { + if (NT_STATUS_IS_OK(pipe_cm_find(ipc, interface, presult))) { return NT_STATUS_OK; } - return pipe_cm_connect(ctx, cli, interface, presult); + return pipe_cm_connect(ctx, ipc, interface, presult); } /******************************************************************** @@ -189,18 +227,18 @@ WERROR libnetapi_open_pipe(struct libnetapi_ctx *ctx, struct rpc_pipe_client *result = NULL; NTSTATUS status; WERROR werr; - struct cli_state *cli = NULL; + struct client_ipc_connection *ipc = NULL; if (!presult) { return WERR_INVALID_PARAM; } - werr = libnetapi_open_ipc_connection(ctx, server_name, &cli); + werr = libnetapi_open_ipc_connection(ctx, server_name, &ipc); if (!W_ERROR_IS_OK(werr)) { return werr; } - status = pipe_cm_open(ctx, cli, interface, &result); + status = pipe_cm_open(ctx, ipc, interface, &result); if (!NT_STATUS_IS_OK(status)) { libnetapi_set_error_string(ctx, "failed to open PIPE %s: %s", get_pipe_name_from_syntax(talloc_tos(), interface), diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index effe2eb..d0f7756 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -43,6 +43,7 @@ struct libnetapi_private_ctx { struct policy_handle builtin_handle; } samr; + struct client_ipc_connection *ipc_connections; }; NET_API_STATUS libnetapi_get_password(struct libnetapi_ctx *ctx, char **password); -- Samba Shared Repository