]> err.no Git - util-linux/commitdiff
losetup: do not distinguish between malloc and realloc
authorTobias Klauser <tklauser@distanz.ch>
Wed, 11 Aug 2010 21:12:07 +0000 (23:12 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 20 Aug 2010 11:05:21 +0000 (13:05 +0200)
realloc(NULL, size) behaves the same as malloc(size) so there is no need
to distinguish between the two.

[kzak@redhat.com: - better handle realloc() errors]

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Karel Zak <kzak@redhat.com>
mount/lomount.c

index 54b9f8e9aad075c7bbf821d1ffa5b557bbe326fb..03aae4b2aa4539af0fb0164ac9081ac488767132 100644 (file)
@@ -258,11 +258,16 @@ loop_scandir(const char *dirname, int **ary, int hasprefix)
                if (n == -1 || n < NLOOPS_DEFAULT)
                        continue;
                if (count + 1 > arylen) {
+                       int *tmp;
+
                        arylen += 1;
-                       *ary = *ary ? realloc(*ary, arylen * sizeof(int)) :
-                                     malloc(arylen * sizeof(int));
-                       if (!*ary)
+
+                       tmp = realloc(*ary, arylen * sizeof(int));
+                       if (!tmp) {
+                               free(*ary);
                                return -1;
+                       }
+                       *ary = tmp;
                }
                (*ary)[count++] = n;
        }