From: Tim Potter Date: Mon, 6 Aug 2001 02:18:40 +0000 (+0000) Subject: Cleaned up error handling in cli_initialise() to fix a memleak found by X-Git-Tag: samba-2.2.5pre1~1693^2~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b5373f4b59cfe1cffe915e5d4eb29ed83fe99ba6;p=thirdparty%2Fsamba.git Cleaned up error handling in cli_initialise() to fix a memleak found by Claudia Moroder --- diff --git a/source/libsmb/clientgen.c b/source/libsmb/clientgen.c index e9f55850ac1..79fa224e8f0 100644 --- a/source/libsmb/clientgen.c +++ b/source/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; } /****************************************************************************