Commit 7bc9e2aa2fe4b554021129fabb8a46b5a33ed4e9

Carlos Martín Nieto 2011-05-31T15:06:22

Guard against double-freeing the current section If parse_section_header{,_ext} return an error, current_section doesn't get allocated. Set it to NULL after freeing so we don't try to free it again. This fixes part 2-2 of Issue #210. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>

diff --git a/src/config_file.c b/src/config_file.c
index e468a0b..37e3f1f 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -808,6 +808,7 @@ static int config_parse(diskfile_backend *cfg_file)
 
 		case '[': /* section header, new section begins */
 			free(current_section);
+			current_section = NULL;
 			error = parse_section_header(cfg_file, &current_section);
 			break;
 
@@ -847,8 +848,7 @@ static int config_parse(diskfile_backend *cfg_file)
 		}
 	}
 
-	if (current_section)
-		free(current_section);
+	free(current_section);
 
 	return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to parse config");
 }