From 72c0373f795a5c326e6bd0f7469601f492124d70 Mon Sep 17 00:00:00 2001 From: Florian Zumbiehl Date: Sat, 29 Aug 2009 16:25:47 +0200 Subject: util_lookup_group(): fix memory leak if realloc() fails --- libudev/libudev-util-private.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libudev/libudev-util-private.c') diff --git a/libudev/libudev-util-private.c b/libudev/libudev-util-private.c index 5b5ecb1f50..b33ee79d6b 100644 --- a/libudev/libudev-util-private.c +++ b/libudev/libudev-util-private.c @@ -154,9 +154,12 @@ gid_t util_lookup_group(struct udev *udev, const char *group) buf = NULL; gid = 0; for (;;) { - buf = realloc(buf, buflen); - if (!buf) + char *newbuf; + + newbuf = realloc(buf, buflen); + if (!newbuf) break; + buf = newbuf; errno = getgrnam_r(group, &grbuf, buf, buflen, &gr); if (gr != NULL) { gid = gr->gr_gid; -- cgit v1.2.3-54-g00ecf