util_lookup_group(): fix memory leak if realloc() fails

This commit is contained in:
Florian Zumbiehl
2009-08-29 16:25:47 +02:00
committed by Kay Sievers
parent f46b9c2628
commit 72c0373f79
+5 -2
View File
@@ -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;