diff options
author | robert <robert@FreeBSD.org> | 2003-03-19 14:01:35 +0000 |
---|---|---|
committer | robert <robert@FreeBSD.org> | 2003-03-19 14:01:35 +0000 |
commit | 791c39f548db6fb2fb0c90923d3e40831d869955 (patch) | |
tree | 4ec1c3c579945c4d6c3e4d58574ebcf00bb1a100 | |
parent | c56269f940416758dd06595761de0c52aed5f1ff (diff) | |
download | FreeBSD-src-791c39f548db6fb2fb0c90923d3e40831d869955.zip FreeBSD-src-791c39f548db6fb2fb0c90923d3e40831d869955.tar.gz |
If realloc(3) fails in copyline(), do not make matters worse by
leaving without deallocating `data' thereby creating a memory leak.
-rw-r--r-- | lib/libc/gen/getgrent.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index ec423a4..a073946 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -293,9 +293,12 @@ _dns_grscan(rv, cb_data, ap) } /* only check first elem */ - if (copyline(hp[0]) == 0) - return NS_UNAVAIL; + r = copyline(hp[0]); hesiod_free_list(context, hp); + if (r == 0) { + r = NS_UNAVAIL; + break; + } if (matchline(search, gid, name)) { r = NS_SUCCESS; break; @@ -360,9 +363,10 @@ _nis_grscan(rv, cb_data, ap) return NS_UNAVAIL; } data[datalen] = '\0'; /* clear trailing \n */ - if (copyline(data) == 0) - return NS_UNAVAIL; + r = copyline(data); free(data); + if (r == 0) + return NS_UNAVAIL; if (matchline(search, gid, name)) return NS_SUCCESS; else @@ -410,9 +414,10 @@ _nis_grscan(rv, cb_data, ap) } } data[datalen] = '\0'; /* clear trailing \n */ - if (copyline(data) == 0) - return NS_UNAVAIL; + r = copyline(data); free(data); + if (r == 0) + return NS_UNAVAIL; if (matchline(search, gid, name)) return NS_SUCCESS; } |