config.c: handle lock file in error case in git_config_rename_...
We could rely on atexit() to clean up everything, but let's be explicit when we can. And it's good anyway because the function is called the second time in the same process, we're in trouble. This function should not affect the successful case because after commit_lock_file() is called, rollback_lock_file() becomes no-op, as long as it is initialized. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Dec 20, 2016 at 16:48 UTC
c06fa62dfc9c882f60250e60ad91fbb6a7e6f8e7
1 file changed
+3
-1
config.c
+3
-1
@@ -2314,7 +2314,7 @@ int git_config_rename_section_in_file(const char *config_filename,
2314
2315
if (new_name && !section_name_is_ok(new_name)) {
2316
ret = error("invalid section name: %s", new_name);
2317
- goto out;
2317
+ goto out_no_rollback;
2318
}
2319
2320
if (!config_filename)
@@ -2396,6 +2396,8 @@ commit_and_out:
2396
ret = error_errno("could not write config file %s",
2397
config_filename);
2398
out:
2399
+ rollback_lock_file(lock);
2400
+out_no_rollback:
2401
free(filename_buf);
2402
return ret;
2403
}