From: Ramiro Polla Date: Sun, 28 Feb 2010 00:46:13 +0000 (-0300) Subject: Always close(fd) as soon as file is mmap()'d. X-Git-Tag: v3.0pre0~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=38926cce43c3c848b0da2148862ce9606dd99541;p=thirdparty%2Fccache.git Always close(fd) as soon as file is mmap()'d. --- diff --git a/ccache.c b/ccache.c index f37d23997..8bcef371d 100644 --- a/ccache.c +++ b/ccache.c @@ -348,6 +348,7 @@ static void remember_include_file(char *path, size_t path_len) goto failure; } data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + close(fd); if (data == (char *)-1) { cc_log("Failed to mmap %s", path); goto failure; @@ -422,11 +423,11 @@ static int process_preprocessed_file(struct mdfour *hash, const char *path) } size = st.st_size; data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + close(fd); if (data == (void *)-1) { cc_log("Failed to mmap %s", path); return 0; } - close(fd); if (enable_direct) { included_files = create_hashtable(1000, hash_from_string, diff --git a/unify.c b/unify.c index b001a520b..038705cb2 100644 --- a/unify.c +++ b/unify.c @@ -261,11 +261,11 @@ int unify_hash(struct mdfour *hash, const char *fname) lines in preprocessor output. I have seen lines of over 100k in length, so this is well worth it */ map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + close(fd); if (map == (char *)-1) { cc_log("Failed to mmap %s", fname); return -1; } - close(fd); /* pass it through the unifier */ unify(hash, (unsigned char *)map, st.st_size);