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>
Junio C Hamano committed
May 7, 2006 at 21:27 UTC
f8ba655ee4131e5c73c28a4ea854b24ce4058e1e
1 file changed
+6
-12
config.c
+6
-12
@@ -420,7 +420,7 @@ int git_config_set_multivar(const char* key, const char* value,
420
const char* value_regex, int multi_replace)
421
{
422
int i;
423
- int fd, in_fd;
423
+ int fd = -1, in_fd;
424
int ret;
425
char* config_filename = strdup(git_path("config"));
426
char* lock_file = strdup(git_path("config.lock"));
@@ -478,15 +478,11 @@ int git_config_set_multivar(const char* key, const char* value,
478
if ( ENOENT != errno ) {
479
error("opening %s: %s", config_filename,
480
strerror(errno));
481
- close(fd);
482
- unlink(lock_file);
481
ret = 3; /* same as "invalid config file" */
482
goto out_free;
483
}
484
/* if nothing to unset, error out */
485
if (value == NULL) {
488
- close(fd);
489
- unlink(lock_file);
486
ret = 5;
487
goto out_free;
488
}
@@ -514,8 +510,6 @@ int git_config_set_multivar(const char* key, const char* value,
510
fprintf(stderr, "Invalid pattern: %s\n",
511
value_regex);
512
free(store.value_regex);
517
- close(fd);
518
- unlink(lock_file);
513
ret = 6;
514
goto out_free;
515
}
@@ -551,8 +545,6 @@ int git_config_set_multivar(const char* key, const char* value,
545
/* if nothing to unset, or too many matches, error out */
546
if ((store.seen == 0 && value == NULL) ||
547
(store.seen > 1 && multi_replace == 0)) {
554
- close(fd);
555
- unlink(lock_file);
548
ret = 5;
549
goto out_free;
550
}
@@ -601,8 +593,6 @@ int git_config_set_multivar(const char* key, const char* value,
593
unlink(config_filename);
594
}
595
604
- close(fd);
605
-
596
if (rename(lock_file, config_filename) < 0) {
597
fprintf(stderr, "Could not rename the lock file?\n");
598
ret = 4;
@@ -612,10 +602,14 @@ int git_config_set_multivar(const char* key, const char* value,
602
ret = 0;
603
604
out_free:
605
+ if (0 <= fd)
606
+ close(fd);
607
if (config_filename)
608
free(config_filename);
617
- if (lock_file)
609
+ if (lock_file) {
610
+ unlink(lock_file);
611
free(lock_file);
612
+ }
613
return ret;
614
}
615