Merge branch 'ss/fix-config-fd-leak'
authorJunio C Hamano <gitster@pobox.com>
Wed, 26 Aug 2015 22:45:30 +0000 (15:45 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 26 Aug 2015 22:45:30 +0000 (15:45 -0700)
* ss/fix-config-fd-leak:
config: close config file handle in case of error

1  2 
config.c
diff --combined config.c
index a34b850cdc3f6902882c04f925456b4877978729,83caa2546ee2e93bfb5cb1269bde4ea4e983a9f3..c027e6fbe035e118cc461423f935714e30d6768c
+++ 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;
                        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;
        }
  
                                }
                                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;
                                }
                                /*
                        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;
                }
        }