From: Michael Huang Date: Mon, 11 Jul 2011 14:06:49 +0000 (+0100) Subject: Close the file descriptor along the writable path. X-Git-Tag: 1.2.8~6 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=00da6d769e4e736ebc6dca2e634fae15c0a0c3d2;p=hivex.git 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. --- 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);