git_config_rename_section_in_file(): avoid resource leak

In case of errors, we really want the file descriptor to be closed. Discovered by a Coverity scan. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed May 4, 2017 at 15:55 UTC 4db7dbdb4ae5426ab133b3844ea2a6889c6897d7
1 file changed +4 -1
config.c
+4 -1
@@ -2621,7 +2621,7 @@ int git_config_rename_section_in_file(const char *config_filename,
2621 struct lock_file *lock;
2622 int out_fd;
2623 char buf[1024];
2624 - FILE *config_file;
2624 + FILE *config_file = NULL;
2625 struct stat st;
2626
2627 if (new_name && !section_name_is_ok(new_name)) {
@@ -2703,11 +2703,14 @@ int git_config_rename_section_in_file(const char *config_filename,
2703 }
2704 }
2705 fclose(config_file);
2706 + config_file = NULL;
2707 commit_and_out:
2708 if (commit_lock_file(lock) < 0)
2709 ret = error_errno("could not write config file %s",
2710 config_filename);
2711 out:
2712 + if (config_file)
2713 + fclose(config_file);
2714 rollback_lock_file(lock);
2715 out_no_rollback:
2716 free(filename_buf);