diff options
author | Noel Power <noel.power@suse.com> | 2019-05-22 11:09:41 +0000 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2019-06-04 22:13:07 +0000 |
commit | f3f79a267ee656f22df01e8a7bb9d4db64e78781 (patch) | |
tree | 317784e206967269296f171310657fcc742f2379 /nsswitch | |
parent | 9c7113a418ce169b486f86238643e2d03112410b (diff) | |
download | samba-f3f79a267ee656f22df01e8a7bb9d4db64e78781.tar.gz |
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 <noel.power@suse.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'nsswitch')
-rw-r--r-- | nsswitch/nsstest.c | 6 |
1 files changed, 6 insertions, 0 deletions
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; |