From: Tobias Klauser Date: Wed, 11 Aug 2010 21:12:07 +0000 (+0200) Subject: losetup: do not distinguish between malloc and realloc X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9695a7c653c5e1871f7bb78fa0e6ec8d4e74a83a;p=util-linux losetup: do not distinguish between malloc and realloc 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 Signed-off-by: Karel Zak --- diff --git a/mount/lomount.c b/mount/lomount.c index 54b9f8e9..03aae4b2 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -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; }