From: Junio C Hamano Date: Wed, 26 Aug 2015 22:45:30 +0000 (-0700) Subject: Merge branch 'ss/fix-config-fd-leak' X-Git-Tag: v2.6.0-rc0~42 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/51e83a4898b47ff3286f1cff65c3715ee803ade9?hp=-c Merge branch 'ss/fix-config-fd-leak' * ss/fix-config-fd-leak: config: close config file handle in case of error --- 51e83a4898b47ff3286f1cff65c3715ee803ade9 diff --combined config.c index a34b850cdc,83caa2546e..c027e6fbe0 --- a/config.c +++ b/config.c @@@ -1935,7 -1935,7 +1935,7 @@@ int git_config_set_multivar_in_file(con const char *key, const char *value, const char *value_regex, int multi_replace) { - int fd = -1, in_fd; + int fd = -1, in_fd = -1; int ret; struct lock_file *lock = NULL; char *filename_buf = NULL; @@@ -2065,10 -2065,11 +2065,11 @@@ goto out_free; } close(in_fd); + in_fd = -1; - if (chmod(lock->filename.buf, st.st_mode & 07777) < 0) { + if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) { error("chmod on %s failed: %s", - lock->filename.buf, strerror(errno)); + get_lock_file_path(lock), strerror(errno)); ret = CONFIG_NO_WRITE; goto out_free; } @@@ -2148,10 -2149,12 +2149,12 @@@ out_free free(filename_buf); if (contents) munmap(contents, contents_sz); + if (in_fd >= 0) + close(in_fd); return ret; write_err_out: - ret = write_error(lock->filename.buf); + ret = write_error(get_lock_file_path(lock)); goto out_free; } @@@ -2252,9 -2255,9 +2255,9 @@@ int git_config_rename_section_in_file(c fstat(fileno(config_file), &st); - if (chmod(lock->filename.buf, st.st_mode & 07777) < 0) { + if (chmod(get_lock_file_path(lock), st.st_mode & 07777) < 0) { ret = error("chmod on %s failed: %s", - lock->filename.buf, strerror(errno)); + get_lock_file_path(lock), strerror(errno)); goto out; } @@@ -2275,7 -2278,7 +2278,7 @@@ } store.baselen = strlen(new_name); if (!store_write_section(out_fd, new_name)) { - ret = write_error(lock->filename.buf); + ret = write_error(get_lock_file_path(lock)); goto out; } /* @@@ -2301,7 -2304,7 +2304,7 @@@ continue; length = strlen(output); if (write_in_full(out_fd, output, length) != length) { - ret = write_error(lock->filename.buf); + ret = write_error(get_lock_file_path(lock)); goto out; } }