]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
read_file(): Allocate memory only if the file exists
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 25 Aug 2010 20:10:27 +0000 (22:10 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 25 Aug 2010 20:10:27 +0000 (22:10 +0200)
util.c

diff --git a/util.c b/util.c
index f445f881bd716f69384be56ccd66d2d2ee5e5482..2779971d09a1def2f06ab4efb00d8478e06433f5 100644 (file)
--- 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;