Skip to content

Commit 4db7dbd

Browse files
dschogitster
authored andcommitted
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>
1 parent 5748693 commit 4db7dbd

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

config.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2621,7 +2621,7 @@ int git_config_rename_section_in_file(const char *config_filename,
26212621
struct lock_file *lock;
26222622
int out_fd;
26232623
char buf[1024];
2624-
FILE *config_file;
2624+
FILE *config_file = NULL;
26252625
struct stat st;
26262626

26272627
if (new_name && !section_name_is_ok(new_name)) {
@@ -2703,11 +2703,14 @@ int git_config_rename_section_in_file(const char *config_filename,
27032703
}
27042704
}
27052705
fclose(config_file);
2706+
config_file = NULL;
27062707
commit_and_out:
27072708
if (commit_lock_file(lock) < 0)
27082709
ret = error_errno("could not write config file %s",
27092710
config_filename);
27102711
out:
2712+
if (config_file)
2713+
fclose(config_file);
27112714
rollback_lock_file(lock);
27122715
out_no_rollback:
27132716
free(filename_buf);

0 commit comments

Comments
 (0)