Always close(fd) as soon as file is mmap()'d.

This commit is contained in:
Ramiro Polla 2010-02-27 21:46:13 -03:00 committed by Joel Rosdahl
parent 1c31b315b4
commit 38926cce43
2 changed files with 3 additions and 2 deletions

View File

@ -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,

View File

@ -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);