From: Joel Rosdahl Date: Wed, 25 Aug 2010 20:10:27 +0000 (+0200) Subject: read_file(): Allocate memory only if the file exists X-Git-Tag: v3.1~55 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cd9eadfef518bf44ad32a197bf2136c6bf5ee0f2;p=thirdparty%2Fccache.git read_file(): Allocate memory only if the file exists --- diff --git a/util.c b/util.c index f445f881b..2779971d0 100644 --- a/util.c +++ b/util.c @@ -1152,13 +1152,13 @@ read_file(const char *path) { int fd, ret; size_t pos = 0, allocated = 1024; - char *result = malloc(allocated); + char *result; fd = open(path, O_RDONLY); if (fd == -1) { - free(result); return NULL; } + result = x_malloc(allocated); ret = 0; do { pos += ret;