Browse Source

Fix repo-config set-multivar error return path.

This hopefully fixes the problem an earlier commit 5d8ee9ceb attemted
to fix.

Signed-off-by: Junio C Hamano <junkio@cox.net>
maint
Junio C Hamano 19 years ago
parent
commit
f8ba655ee4
  1. 18
      config.c

18
config.c

@ -420,7 +420,7 @@ int git_config_set_multivar(const char* key, const char* value,
const char* value_regex, int multi_replace) const char* value_regex, int multi_replace)
{ {
int i; int i;
int fd, in_fd; int fd = -1, in_fd;
int ret; int ret;
char* config_filename = strdup(git_path("config")); char* config_filename = strdup(git_path("config"));
char* lock_file = strdup(git_path("config.lock")); char* lock_file = strdup(git_path("config.lock"));
@ -478,15 +478,11 @@ int git_config_set_multivar(const char* key, const char* value,
if ( ENOENT != errno ) { if ( ENOENT != errno ) {
error("opening %s: %s", config_filename, error("opening %s: %s", config_filename,
strerror(errno)); strerror(errno));
close(fd);
unlink(lock_file);
ret = 3; /* same as "invalid config file" */ ret = 3; /* same as "invalid config file" */
goto out_free; goto out_free;
} }
/* if nothing to unset, error out */ /* if nothing to unset, error out */
if (value == NULL) { if (value == NULL) {
close(fd);
unlink(lock_file);
ret = 5; ret = 5;
goto out_free; goto out_free;
} }
@ -514,8 +510,6 @@ int git_config_set_multivar(const char* key, const char* value,
fprintf(stderr, "Invalid pattern: %s\n", fprintf(stderr, "Invalid pattern: %s\n",
value_regex); value_regex);
free(store.value_regex); free(store.value_regex);
close(fd);
unlink(lock_file);
ret = 6; ret = 6;
goto out_free; goto out_free;
} }
@ -551,8 +545,6 @@ int git_config_set_multivar(const char* key, const char* value,
/* if nothing to unset, or too many matches, error out */ /* if nothing to unset, or too many matches, error out */
if ((store.seen == 0 && value == NULL) || if ((store.seen == 0 && value == NULL) ||
(store.seen > 1 && multi_replace == 0)) { (store.seen > 1 && multi_replace == 0)) {
close(fd);
unlink(lock_file);
ret = 5; ret = 5;
goto out_free; goto out_free;
} }
@ -601,8 +593,6 @@ int git_config_set_multivar(const char* key, const char* value,
unlink(config_filename); unlink(config_filename);
} }


close(fd);

if (rename(lock_file, config_filename) < 0) { if (rename(lock_file, config_filename) < 0) {
fprintf(stderr, "Could not rename the lock file?\n"); fprintf(stderr, "Could not rename the lock file?\n");
ret = 4; ret = 4;
@ -612,10 +602,14 @@ int git_config_set_multivar(const char* key, const char* value,
ret = 0; ret = 0;


out_free: out_free:
if (0 <= fd)
close(fd);
if (config_filename) if (config_filename)
free(config_filename); free(config_filename);
if (lock_file) if (lock_file) {
unlink(lock_file);
free(lock_file); free(lock_file);
}
return ret; return ret;
} }



Loading…
Cancel
Save