From 003c1f1171f12678fe7994b3e6b3f6b2f2b88de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Justo?= Date: Sun, 11 Jun 2023 20:49:28 +0200 Subject: config: fix a leak in git_config_copy_or_rename_section_in_file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In 52d59cc645 (branch: add a --copy (-c) option to go with --move (-m), 2017-06-18) a new strbuf variable was introduced, but not released. Thus, when copying a branch that has any configuration, we have a leak. $ git branch foo $ git config branch.foo.some-key some_value $ git branch -c foo bar Direct leak of 65 byte(s) in 1 object(s) allocated from: ... in xrealloc wrapper.c ... in strbuf_grow strbuf.c ... in strbuf_vaddf strbuf.c ... in strbuf_addf strbuf.c ... in store_create_section config.c ... in git_config_copy_or_rename_section_in_file config.c ... in git_config_copy_section_in_file config.c ... in git_config_copy_section config.c ... in copy_or_rename_branch builtin/branch.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c Let's fix that leak. Signed-off-by: Rubén Justo Signed-off-by: Junio C Hamano --- config.c | 1 + 1 file changed, 1 insertion(+) (limited to 'config.c') diff --git a/config.c b/config.c index b79baf83e3..39a7d7422c 100644 --- a/config.c +++ b/config.c @@ -3879,6 +3879,7 @@ out_no_rollback: free(filename_buf); config_store_data_clear(&store); strbuf_release(&buf); + strbuf_release(©str); return ret; } -- cgit v1.2.3 From 5e786ed3ee109f166b05916f3f5410f76164f8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Justo?= Date: Sat, 17 Jun 2023 08:41:40 +0200 Subject: config: fix a leak in git_config_copy_or_rename_section_in_file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A branch can have its configuration spread over several configuration sections. This situation was already foreseen in 52d59cc645 (branch: add a --copy (-c) option to go with --move (-m), 2017-06-18) when "branch -c" was introduced. Unfortunately, a leak was also introduced: $ git branch foo $ cat >> .git/config < Signed-off-by: Junio C Hamano --- config.c | 1 + 1 file changed, 1 insertion(+) (limited to 'config.c') diff --git a/config.c b/config.c index 39a7d7422c..207e4394a3 100644 --- a/config.c +++ b/config.c @@ -3833,6 +3833,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename output[0] = '\t'; } } else { + strbuf_release(©str); copystr = store_create_section(new_name, &store); } } -- cgit v1.2.3