From c665188f58d0f1dbad8f358b3e79b0f41e2bdd39 Mon Sep 17 00:00:00 2001 From: hargagan Date: Mon, 30 Nov 2015 14:39:55 +0530 Subject: [PATCH] Fix for memory leak due to dangling cli connection structures left after smbc_free_context(). Signed-off-by: hargagan --- source3/libsmb/clientgen.c | 20 ++++++++++++++++++++ source3/libsmb/libsmb_server.c | 6 +++--- source3/libsmb/proto.h | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index 6f28dfa..c85daba 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -278,6 +278,26 @@ static void _cli_shutdown(struct cli_state *cli) TALLOC_FREE(cli); } +void cli_cleanup(struct cli_state *cli) +{ + struct cli_state *cli_head; + if (cli == NULL) { + return; + } + DLIST_HEAD(cli, cli_head); + /* + * Go to the head and start the cleanup of all in the + * connections list. + */ + struct cli_state *p, *next; + + for (p = cli_head; p; p = next) { + next = p->next; + DLIST_REMOVE(cli_head, p); + _cli_shutdown(p); + } +} + void cli_shutdown(struct cli_state *cli) { struct cli_state *cli_head; diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c index 07d51ea..a4b8939 100644 --- a/source3/libsmb/libsmb_server.c +++ b/source3/libsmb/libsmb_server.c @@ -89,7 +89,7 @@ SMBC_remove_unused_server(SMBCCTX * context, for (file = context->internal->files; file; file = file->next) { if (file->srv == srv) { /* Still used */ - DEBUG(3, ("smbc_remove_usused_server: " + DEBUG(3, ("smbc_remove_unused_server: " "%p still used by %p.\n", srv, file)); return 1; @@ -98,10 +98,10 @@ SMBC_remove_unused_server(SMBCCTX * context, DLIST_REMOVE(context->internal->servers, srv); - cli_shutdown(srv->cli); + cli_cleanup(srv->cli); srv->cli = NULL; - DEBUG(3, ("smbc_remove_usused_server: %p removed.\n", srv)); + DEBUG(3, ("smbc_remove_unused_server: %p removed.\n", srv)); smbc_getFunctionRemoveCachedServer(context)(context, srv); diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h index 5ebcf5f..a48551f 100644 --- a/source3/libsmb/proto.h +++ b/source3/libsmb/proto.h @@ -170,6 +170,7 @@ struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx, int flags); void cli_nt_pipes_close(struct cli_state *cli); void cli_shutdown(struct cli_state *cli); +void cli_cleanup(struct cli_state *cli); const char *cli_state_remote_realm(struct cli_state *cli); uint16_t cli_state_get_vc_num(struct cli_state *cli); uint16_t cli_setpid(struct cli_state *cli, uint16_t pid); -- 2.1.4