From 989ad44d32c2e77972a966d91f1813b0b929f83b Mon Sep 17 00:00:00 2001 From: todd stecher Date: Mon, 19 Jan 2009 15:09:51 -0800 Subject: Memory leaks and other fixes found by Coverity --- source3/lib/dprintf.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/dprintf.c b/source3/lib/dprintf.c index b3c830dd5b..631c45a807 100644 --- a/source3/lib/dprintf.c +++ b/source3/lib/dprintf.c @@ -32,24 +32,27 @@ int d_vfprintf(FILE *f, const char *format, va_list ap) { - char *p, *p2; + char *p = NULL, *p2 = NULL; int ret, maxlen, clen; const char *msgstr; va_list ap2; + va_copy(ap2, ap); + /* do any message translations */ msgstr = lang_msg(format); - if (!msgstr) return -1; - - va_copy(ap2, ap); + if (!msgstr) { + ret = -1; + goto out; + } ret = vasprintf(&p, msgstr, ap2); lang_msg_free(msgstr); if (ret <= 0) { - va_end(ap2); - return ret; + ret = -1; + goto out; } /* now we have the string in unix format, convert it to the display @@ -58,10 +61,10 @@ again: p2 = (char *)SMB_MALLOC(maxlen); if (!p2) { - SAFE_FREE(p); - va_end(ap2); - return -1; + ret = -1; + goto out; } + clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen, True); if (clen >= maxlen) { @@ -72,10 +75,11 @@ again: } /* good, its converted OK */ - SAFE_FREE(p); ret = fwrite(p2, 1, clen, f); - SAFE_FREE(p2); +out: + SAFE_FREE(p); + SAFE_FREE(p2); va_end(ap2); return ret; -- cgit