diff options
author | Junio C Hamano <junkio@cox.net> | 2006-12-19 21:55:27 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-12-19 22:30:59 -0800 |
commit | fc1905bb9340304fb5980841fca24638028c1c5e (patch) | |
tree | 593c15e05706a0f1e607b55dc7385b64a1ff908e /config.c | |
parent | c17f9f12a4a8d224e5cff6bcfa6191450f90fa0b (diff) | |
download | git-fc1905bb9340304fb5980841fca24638028c1c5e.tar.gz git-fc1905bb9340304fb5980841fca24638028c1c5e.tar.xz |
config_rename_section: fix FILE* leak
Noticed by SungHyun Nam.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -749,7 +749,7 @@ out_free: int git_config_rename_section(const char *old_name, const char *new_name) { int ret = 0; - const char *config_filename; + char *config_filename; struct lock_file *lock = xcalloc(sizeof(struct lock_file), 1); int out_fd; char buf[1024]; @@ -762,11 +762,15 @@ int git_config_rename_section(const char *old_name, const char *new_name) } config_filename = xstrdup(config_filename); out_fd = hold_lock_file_for_update(lock, config_filename, 0); - if (out_fd < 0) - return error("Could not lock config file!"); + if (out_fd < 0) { + ret = error("Could not lock config file!"); + goto out; + } - if (!(config_file = fopen(config_filename, "rb"))) - return error("Could not open config file!"); + if (!(config_file = fopen(config_filename, "rb"))) { + ret = error("Could not open config file!"); + goto out; + } while (fgets(buf, sizeof(buf), config_file)) { int i; @@ -806,8 +810,11 @@ int git_config_rename_section(const char *old_name, const char *new_name) } write(out_fd, buf, strlen(buf)); } + fclose(config_file); if (close(out_fd) || commit_lock_file(lock) < 0) - return error("Cannot commit config file!"); + ret = error("Cannot commit config file!"); + out: + free(config_filename); return ret; } |