threads / discuss / 32258

Also close config file handle when leaving git_config_set_multivar_in_file() early

Subject: Also close config file handle when leaving git_config_set_multivar_in_file() early

## tl;dr

One message between Dec 1, 2012 and Dec 1, 2012.

replies: 0people: 1as markdown or json

乙酸鋰· Dec 1, 2012, 14:01 UTC · lore
Hi,

This patch fixes the captioned problem. It is needed because our program statically link git. In this case, do not assume a fail will call die() and exit program so the handle is leave not closed.

Regards, ch3cooli

From 5d8d28f039b4db7b4f040a40fdc2edf866200f0c Mon Sep 17 00:00:00 2001
From: Sup Yut Sum <ch3cooli@gmail.com>
Date: Sat, 1 Dec 2012 21:56:41 +0800
Subject: [PATCH] Also close config file handle when leaving
 git_config_set_multivar_in_file() early
Signed-off-by: Sup Yut Sum <ch3cooli@gmail.com>
---
 config.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/config.c b/config.c
index fff8a43..4b5c877 100644
--- a/config.c
+++ b/config.c
@@ -1424,6 +1424,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
 		contents = xmmap(NULL, contents_sz, PROT_READ,
 			MAP_PRIVATE, in_fd, 0);
 		close(in_fd);
+		in_fd = -1;
 
 		if (store.seen == 0)
 			store.seen = 1;
@@ -1493,6 +1494,8 @@ out_free:
 	if (lock)
 		rollback_lock_file(lock);
 	free(filename_buf);
+	if (in_fd >= 0)
+		close(in_fd);
 	return ret;
 
 write_err_out:
-- 
1.8.0.msysgit.0

← back to recent threads