From 9f08cea054e7c2a3fd3b32d9c6711a269704d20b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 6 Aug 2001 02:18:40 +0000 Subject: Cleaned up error handling in cli_initialise() to fix a memleak found by Claudia Moroder (This used to be commit b5373f4b59cfe1cffe915e5d4eb29ed83fe99ba6) --- source3/libsmb/clientgen.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index e9f55850ac..79fa224e8f 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -180,24 +180,28 @@ struct cli_state *cli_initialise(struct cli_state *cli) cli->oplock_handler = cli_oplock_ack; if (!cli->outbuf || !cli->inbuf) - { - return NULL; - } + goto error; - if ((cli->mem_ctx = talloc_init()) == NULL) { - free(cli->outbuf); - free(cli->inbuf); - return NULL; - } + if ((cli->mem_ctx = talloc_init()) == NULL) + goto error; - memset(cli->outbuf, '\0', cli->bufsize); - memset(cli->inbuf, '\0', cli->bufsize); + memset(cli->outbuf, 0, cli->bufsize); + memset(cli->inbuf, 0, cli->bufsize); cli->nt_pipe_fnum = 0; cli->initialised = 1; return cli; + + /* Clean up after malloc() error */ + + error: + + safe_free(cli->inbuf); + safe_free(cli->outbuf); + + return NULL; } /**************************************************************************** -- cgit