diff options
author | Michael Huang <Michael.Huang@visionsolutions.com> | 2011-07-11 15:06:49 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2011-07-11 15:06:49 +0100 |
commit | 00da6d769e4e736ebc6dca2e634fae15c0a0c3d2 (patch) | |
tree | 5d0d23375e43fefd4b316b064a5836844f8c5836 | |
parent | 9863ac20fb262b9c44629d7f65c05c6e0caea215 (diff) | |
download | hivex-00da6d769e4e736ebc6dca2e634fae15c0a0c3d2.tar.gz hivex-00da6d769e4e736ebc6dca2e634fae15c0a0c3d2.tar.xz hivex-00da6d769e4e736ebc6dca2e634fae15c0a0c3d2.zip |
Close the file descriptor along the writable path.
Since the file has been completely read into memory, there is no
reason to keep the file descriptor open.
-rw-r--r-- | lib/hivex.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/hivex.c b/lib/hivex.c index 946ecf3..fedbb6c 100644 --- a/lib/hivex.c +++ b/lib/hivex.c @@ -317,6 +317,13 @@ hivex_open (const char *filename, int flags) if (full_read (h->fd, h->addr, h->size) < h->size) goto error; + + /* We don't need the file descriptor along this path, since we + * have read all the data. + */ + if (close (h->fd) == -1) + goto error; + h->fd = -1; } /* Check header. */ @@ -539,7 +546,10 @@ hivex_close (hive_h *h) munmap (h->addr, h->size); else free (h->addr); - r = close (h->fd); + if (h->fd >= 0) + r = close (h->fd); + else + r = 0; free (h->filename); free (h); |