From: Lucas De Marchi Date: Mon, 12 Dec 2011 20:41:57 +0000 (-0200) Subject: Fix "Dereference of null pointer" as reported by llvm X-Git-Tag: v1~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d51d8bfe25f2a09d3294f60e187b2f74e06aaf6;p=thirdparty%2Fkmod.git Fix "Dereference of null pointer" as reported by llvm --- diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c index e4e0786f..5c25266b 100644 --- a/libkmod/libkmod-index.c +++ b/libkmod/libkmod-index.c @@ -727,19 +727,18 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, DBG(ctx, "file=%s\n", filename); - if ((fd = open(filename, O_RDONLY)) < 0) { + idx = malloc(sizeof(*idx)); + if (idx == NULL) { ERR(ctx, "%m\n"); return NULL; } - fstat(fd, &st); - - idx = malloc(sizeof(*idx)); - if (idx == NULL) { + if ((fd = open(filename, O_RDONLY)) < 0) { ERR(ctx, "%m\n"); - goto fail; + goto fail_open; } + fstat(fd, &st); flags = MAP_PRIVATE; if (populate) flags |= MAP_POPULATE; @@ -776,6 +775,7 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename, fail: close(fd); +fail_open: if (idx->mm) munmap(idx->mm, st.st_size); free(idx);