From 9695a7c653c5e1871f7bb78fa0e6ec8d4e74a83a Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 11 Aug 2010 23:12:07 +0200 Subject: [PATCH] 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 --- mount/lomount.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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; } -- 2.39.5