]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Always close(fd) as soon as file is mmap()'d.
authorRamiro Polla <ramiro@mac-vbox-ubuntu910.(none)>
Sun, 28 Feb 2010 00:46:13 +0000 (21:46 -0300)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 28 Feb 2010 15:41:56 +0000 (16:41 +0100)
ccache.c
unify.c

index f37d239978f05f1d7c12df70b81ffbfe26c486bc..8bcef371de2df386d071170871ed15d4ec6de06b 100644 (file)
--- 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 b001a520b020bc1f4794d8c0da79b0bcdef9c754..038705cb205b1675c916557bcef84a31032c8cd7 100644 (file)
--- 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);