From: Noel Power Date: Wed, 22 May 2019 11:09:41 +0000 (+0000) Subject: nsswitch: cppcheck: Fix memleakOnRealloc errors X-Git-Tag: ldb-2.0.5~508 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3f79a267ee656f22df01e8a7bb9d4db64e78781;p=thirdparty%2Fsamba.git nsswitch: cppcheck: Fix memleakOnRealloc errors Fixes the following errors nsswitch/nsstest.c:192: error: memleakOnRealloc: Common realloc mistake: 'buf' nulled but not freed upon failure <--[cppcheck] nsswitch/nsstest.c:230: error: memleakOnRealloc: Common realloc mistake: 'buf' nulled but not freed upon failure <--[cppcheck] nsswitch/nsstest.c:269: error: memleakOnRealloc: Common realloc mistake: 'buf' nulled but not freed upon failure <--[cppcheck] Signed-off-by: Noel Power Reviewed-by: Andreas Schneider --- diff --git a/nsswitch/nsstest.c b/nsswitch/nsstest.c index 6d92806cffc..e8c4306441d 100644 --- a/nsswitch/nsstest.c +++ b/nsswitch/nsstest.c @@ -188,9 +188,11 @@ static struct group *nss_getgrent(void) again: status = _nss_getgrent_r(&grp, buf, buflen, &nss_errno); if (status == NSS_STATUS_TRYAGAIN) { + char *oldbuf = buf; buflen *= 2; buf = (char *)realloc(buf, buflen); if (!buf) { + SAFE_FREE(oldbuf); return NULL; } goto again; @@ -226,9 +228,11 @@ static struct group *nss_getgrnam(const char *name) again: status = _nss_getgrnam_r(name, &grp, buf, buflen, &nss_errno); if (status == NSS_STATUS_TRYAGAIN) { + char *oldbuf = buf; buflen *= 2; buf = (char *)realloc(buf, buflen); if (!buf) { + SAFE_FREE(oldbuf); return NULL; } goto again; @@ -265,9 +269,11 @@ static struct group *nss_getgrgid(gid_t gid) again: status = _nss_getgrgid_r(gid, &grp, buf, buflen, &nss_errno); if (status == NSS_STATUS_TRYAGAIN) { + char *oldbuf = buf; buflen *= 2; buf = (char *)realloc(buf, buflen); if (!buf) { + SAFE_FREE(oldbuf); return NULL; } goto again;