chiark / gitweb /
util_lookup_group(): fix memory leak if realloc() fails
authorFlorian Zumbiehl <florz@florz.de>
Sat, 29 Aug 2009 14:25:47 +0000 (16:25 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Sat, 29 Aug 2009 14:25:47 +0000 (16:25 +0200)
libudev/libudev-util-private.c

index 5b5ecb1f503c788550b423e7722b6af223e4d6b6..b33ee79d6b4f110d7caae3f44955886322f6f360 100644 (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;