From 00da6d769e4e736ebc6dca2e634fae15c0a0c3d2 Mon Sep 17 00:00:00 2001 From: Michael Huang Date: Mon, 11 Jul 2011 15:06:49 +0100 Subject: [PATCH] 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. --- lib/hivex.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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); -- 1.8.3.1