From aef2a8879198b292401276632f93402f2c715a14 Mon Sep 17 00:00:00 2001 From: pfg Date: Fri, 20 Feb 2015 01:02:32 +0000 Subject: [PATCH] Fix small memleaks in nis_passwd() and nis_group(). These only occur upon error. Code Review: https://reviews.freebsd.org/D1849 Reviewed by: delphij CID: 1016715 CID: 1016717 --- lib/libc/gen/getgrent.c | 4 +++- lib/libc/gen/getpwent.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index 4ba24ae4777f..1f4d7e9fb299 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -1173,8 +1173,10 @@ nis_group(void *retval, void *mdata, va_list ap) * terminator, alignment padding, and one (char *) * pointer for the member list terminator. */ - if (resultlen >= bufsize - _ALIGNBYTES - sizeof(char *)) + if (resultlen >= bufsize - _ALIGNBYTES - sizeof(char *)) { + free(result); goto erange; + } memcpy(buffer, result, resultlen); buffer[resultlen] = '\0'; free(result); diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index 6cd7eaf39b58..0cb8ed227f85 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -1392,8 +1392,10 @@ nis_passwd(void *retval, void *mdata, va_list ap) continue; } } - if (resultlen >= bufsize) + if (resultlen >= bufsize) { + free(result); goto erange; + } memcpy(buffer, result, resultlen); buffer[resultlen] = '\0'; free(result);