summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2011-03-29 12:19:53 +0200
committerCarlos Martín Nieto <cmn@elego.de>2011-03-29 12:19:53 +0200
commit9f7f4122cfa49f8932fd65f9751d96125c8155bc (patch)
tree7c68b483a80a6332a417566433dd2b5ecb7c5e44
parent4e02504f5232e38d116830aaf25bcea4d5123a45 (diff)
downloadlibgit2-9f7f4122cfa49f8932fd65f9751d96125c8155bc.tar.gz
Don't leak if config parsing fails
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
-rw-r--r--src/config.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/config.c b/src/config.c
index 852bcd3b1..22ba5f56d 100644
--- a/src/config.c
+++ b/src/config.c
@@ -74,15 +74,20 @@ int git_config_open(git_config **cfg_out, const char *path)
goto cleanup;
}
- *cfg_out = cfg;
-
error = gitfo_read_file(&cfg->reader.buffer, cfg->file_path);
if(error < GIT_SUCCESS)
goto cleanup;
/* Initialise the reading position */
cfg->reader.read_ptr = cfg->reader.buffer.data;
- return config_parse(cfg);
+
+ error = config_parse(cfg);
+ if(error < GIT_SUCCESS)
+ git_config_free(cfg);
+ else
+ *cfg_out = cfg;
+
+ return error;
cleanup:
if(cfg->vars)