aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric B Munson <emunson@mgebm.net>2012-03-10 15:22:51 -0500
committerEric B Munson <emunson@mgebm.net>2012-03-22 11:57:52 -0400
commit4f5a61606afe6911bd15f1f0645a2240eafbf7ed (patch)
tree9edeafc91255b8af784b9a985a96c0e86eaf86e1
parentde913f90de3c72b3223d4cbae54296cbeaeae4c5 (diff)
downloadlibhugetlbfs-4f5a61606afe6911bd15f1f0645a2240eafbf7ed.tar.gz
Decrement index before closing files on error exit
If obtain_prepared_file fails for any reason, the last fd in our hugetlb segment table will be 0 when the error clean up starts because obtain_prepared_file does not write to the segment structure in error cases. Because the cleanup for loop starts at the segment where obtain_prepared_file failed it will try to close stdout (fd 0). This patch makes the cleanup for loop decrement the index before starting to close file descriptors. Reported-by: Dan Scales <scales@vmware.com> Signed-off-by: Eric B Munson <emunson@mgebm.net>
-rw-r--r--elflink.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/elflink.c b/elflink.c
index c24bedc..e92d2dd 100644
--- a/elflink.c
+++ b/elflink.c
@@ -1321,7 +1321,7 @@ void hugetlbfs_setup_elflink(void)
"%d\n", i);
/* Close files we have already prepared */
- for (; i >= 0; i--)
+ for (i--; i >= 0; i--)
close(htlb_seg_table[i].fd);
return;