mirror of
https://github.com/git/git.git
synced 2026-01-26 02:24:27 +00:00
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>
This commit is contained in:
5
config.c
5
config.c
@@ -2426,7 +2426,7 @@ int git_config_rename_section_in_file(const char *config_filename,
|
||||
struct lock_file *lock;
|
||||
int out_fd;
|
||||
char buf[1024];
|
||||
FILE *config_file;
|
||||
FILE *config_file = NULL;
|
||||
struct stat st;
|
||||
|
||||
if (new_name && !section_name_is_ok(new_name)) {
|
||||
@@ -2508,11 +2508,14 @@ int git_config_rename_section_in_file(const char *config_filename,
|
||||
}
|
||||
}
|
||||
fclose(config_file);
|
||||
config_file = NULL;
|
||||
commit_and_out:
|
||||
if (commit_lock_file(lock) < 0)
|
||||
ret = error_errno("could not write config file %s",
|
||||
config_filename);
|
||||
out:
|
||||
if (config_file)
|
||||
fclose(config_file);
|
||||
rollback_lock_file(lock);
|
||||
out_no_rollback:
|
||||
free(filename_buf);
|
||||
|
||||
Reference in New Issue
Block a user