summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c17f9f1)
raw | patch | inline | side by side (parent: c17f9f1)
author | Junio C Hamano <junkio@cox.net> | |
Wed, 20 Dec 2006 05:55:27 +0000 (21:55 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 20 Dec 2006 06:30:59 +0000 (22:30 -0800) |
Noticed by SungHyun Nam.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
config.c | patch | blob | history |
diff --git a/config.c b/config.c
index 663993fefa9d8c347d2ff4c1b40edbf3b0d19c90..8cbdd178bd9e678774b65cc9ab2da6b169bdc1ca 100644 (file)
--- a/config.c
+++ b/config.c
int git_config_rename_section(const char *old_name, const char *new_name)
{
int ret = 0;
- const char *config_filename;
+ char *config_filename;
struct lock_file *lock = xcalloc(sizeof(struct lock_file), 1);
int out_fd;
char buf[1024];
}
config_filename = xstrdup(config_filename);
out_fd = hold_lock_file_for_update(lock, config_filename, 0);
- if (out_fd < 0)
- return error("Could not lock config file!");
+ if (out_fd < 0) {
+ ret = error("Could not lock config file!");
+ goto out;
+ }
- if (!(config_file = fopen(config_filename, "rb")))
- return error("Could not open config file!");
+ if (!(config_file = fopen(config_filename, "rb"))) {
+ ret = error("Could not open config file!");
+ goto out;
+ }
while (fgets(buf, sizeof(buf), config_file)) {
int i;
}
write(out_fd, buf, strlen(buf));
}
+ fclose(config_file);
if (close(out_fd) || commit_lock_file(lock) < 0)
- return error("Cannot commit config file!");
+ ret = error("Cannot commit config file!");
+ out:
+ free(config_filename);
return ret;
}