This hopefully fixes the problem an earlier commit
5d8ee9ceb attemted
to fix.
Signed-off-by: Junio C Hamano <junkio@cox.net>
const char* value_regex, int multi_replace)
{
int i;
const char* value_regex, int multi_replace)
{
int i;
int ret;
char* config_filename = strdup(git_path("config"));
char* lock_file = strdup(git_path("config.lock"));
int ret;
char* config_filename = strdup(git_path("config"));
char* lock_file = strdup(git_path("config.lock"));
if ( ENOENT != errno ) {
error("opening %s: %s", config_filename,
strerror(errno));
if ( ENOENT != errno ) {
error("opening %s: %s", config_filename,
strerror(errno));
- close(fd);
- unlink(lock_file);
ret = 3; /* same as "invalid config file" */
goto out_free;
}
/* if nothing to unset, error out */
if (value == NULL) {
ret = 3; /* same as "invalid config file" */
goto out_free;
}
/* if nothing to unset, error out */
if (value == NULL) {
- close(fd);
- unlink(lock_file);
ret = 5;
goto out_free;
}
ret = 5;
goto out_free;
}
fprintf(stderr, "Invalid pattern: %s\n",
value_regex);
free(store.value_regex);
fprintf(stderr, "Invalid pattern: %s\n",
value_regex);
free(store.value_regex);
- close(fd);
- unlink(lock_file);
ret = 6;
goto out_free;
}
ret = 6;
goto out_free;
}
/* if nothing to unset, or too many matches, error out */
if ((store.seen == 0 && value == NULL) ||
(store.seen > 1 && multi_replace == 0)) {
/* if nothing to unset, or too many matches, error out */
if ((store.seen == 0 && value == NULL) ||
(store.seen > 1 && multi_replace == 0)) {
- close(fd);
- unlink(lock_file);
ret = 5;
goto out_free;
}
ret = 5;
goto out_free;
}
unlink(config_filename);
}
unlink(config_filename);
}
if (rename(lock_file, config_filename) < 0) {
fprintf(stderr, "Could not rename the lock file?\n");
ret = 4;
if (rename(lock_file, config_filename) < 0) {
fprintf(stderr, "Could not rename the lock file?\n");
ret = 4;
+ if (0 <= fd)
+ close(fd);
if (config_filename)
free(config_filename);
if (config_filename)
free(config_filename);
+ if (lock_file) {
+ unlink(lock_file);