Merge branch 'hv/submodule-config'
[gitweb.git] / config.c
index 9fd275f2c2a46a0f8f5a78db49ba2c6f5635f32f..c027e6fbe035e118cc461423f935714e30d6768c 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1935,7 +1935,7 @@ int git_config_set_multivar_in_file(const char *config_filename,
                                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 @@ int git_config_set_multivar_in_file(const char *config_filename,
                        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 @@ int git_config_set_multivar_in_file(const char *config_filename,
        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 @@ int git_config_rename_section_in_file(const char *config_filename,
 
        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 @@ int git_config_rename_section_in_file(const char *config_filename,
                                }
                                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 @@ int git_config_rename_section_in_file(const char *config_filename,
                        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;
                }
        }