git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 05/11] cat-file: fix a memory leak in --batch-command mode
Date: Thu, 30 Jun 2022 20:00:15 +0200	[thread overview]
Message-ID: <patch-05.11-9ba267377ee-20220630T175714Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-00.11-00000000000-20220630T175714Z-avarab@gmail.com>

Fix a memory leak introduced in 440c705ea63 (cat-file: add
--batch-command mode, 2022-02-18). The free_cmds() function was only
called on "queued_nr" if we had a "flush" command. As the "without
flush for blob info" test added in the same commit shows we can't rely
on that, so let's call free_cmds() again at the end.

Since "nr" follows the usual pattern of being set to 0 if we've
free()'d the memory already it's OK to call it twice, even in cases
where we are doing a "flush".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/cat-file.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 50cf38999d1..ac0459f96be 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -655,6 +655,7 @@ static void batch_objects_command(struct batch_options *opt,
 		free_cmds(queued_cmd, &nr);
 	}
 
+	free_cmds(queued_cmd, &nr);
 	free(queued_cmd);
 	strbuf_release(&input);
 }
-- 
2.37.0.874.g7d3439f13c4


  parent reply	other threads:[~2022-06-30 18:01 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-30 18:00 [PATCH 00/11] built-ins: fix common memory leaks Ævar Arnfjörð Bjarmason
2022-06-30 18:00 ` [PATCH 01/11] check-ref-format: fix trivial memory leak Ævar Arnfjörð Bjarmason
2022-06-30 21:55   ` Junio C Hamano
2022-06-30 18:00 ` [PATCH 02/11] clone: fix memory leak in copy_ref() call Ævar Arnfjörð Bjarmason
2022-06-30 22:03   ` Junio C Hamano
2022-06-30 18:00 ` [PATCH 03/11] submodule.c: free() memory from xgetcwd() Ævar Arnfjörð Bjarmason
2022-06-30 18:00 ` [PATCH 04/11] revert: free "struct replay_opts" members Ævar Arnfjörð Bjarmason
2022-06-30 18:00 ` Ævar Arnfjörð Bjarmason [this message]
2022-06-30 18:00 ` [PATCH 06/11] merge-file: refactor for subsequent memory leak fix Ævar Arnfjörð Bjarmason
2022-06-30 18:00 ` [PATCH 07/11] merge-file: fix memory leaks on error path Ævar Arnfjörð Bjarmason
2022-06-30 18:00 ` [PATCH 08/11] checkout: add a missing clear_unpack_trees_porcelain() Ævar Arnfjörð Bjarmason
2022-06-30 22:20   ` Junio C Hamano
2022-06-30 23:34     ` Ævar Arnfjörð Bjarmason
2022-06-30 23:45       ` Junio C Hamano
2022-06-30 18:00 ` [PATCH 09/11] gc: fix a memory leak Ævar Arnfjörð Bjarmason
2022-06-30 18:00 ` [PATCH 10/11] cat-file: fix a common "struct object_context" " Ævar Arnfjörð Bjarmason
2022-06-30 18:00 ` [PATCH 11/11] pull: fix a "struct oid_array" " Ævar Arnfjörð Bjarmason
2022-07-01 10:42 ` [PATCH v2 00/11] built-ins: fix common memory leaks Ævar Arnfjörð Bjarmason
2022-07-01 10:42   ` [PATCH v2 01/11] check-ref-format: fix trivial memory leak Ævar Arnfjörð Bjarmason
2022-07-01 10:42   ` [PATCH v2 02/11] clone: fix memory leak in wanted_peer_refs() Ævar Arnfjörð Bjarmason
2022-07-01 10:42   ` [PATCH v2 03/11] submodule.c: free() memory from xgetcwd() Ævar Arnfjörð Bjarmason
2022-07-01 10:42   ` [PATCH v2 04/11] revert: free "struct replay_opts" members Ævar Arnfjörð Bjarmason
2022-07-01 10:42   ` [PATCH v2 05/11] cat-file: fix a memory leak in --batch-command mode Ævar Arnfjörð Bjarmason
2022-07-01 10:42   ` [PATCH v2 06/11] merge-file: refactor for subsequent memory leak fix Ævar Arnfjörð Bjarmason
2022-07-01 10:42   ` [PATCH v2 07/11] merge-file: fix memory leaks on error path Ævar Arnfjörð Bjarmason
2022-07-01 10:42   ` [PATCH v2 08/11] checkout: avoid "struct unpack_trees_options" leak Ævar Arnfjörð Bjarmason
2022-07-01 20:25     ` Junio C Hamano
2022-07-01 10:42   ` [PATCH v2 09/11] gc: fix a memory leak Ævar Arnfjörð Bjarmason
2022-07-01 10:42   ` [PATCH v2 10/11] cat-file: fix a common "struct object_context" " Ævar Arnfjörð Bjarmason
2022-07-01 10:43   ` [PATCH v2 11/11] pull: fix a "struct oid_array" " Ævar Arnfjörð Bjarmason
2022-07-01 18:58   ` [PATCH v2 00/11] built-ins: fix common memory leaks Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=patch-05.11-9ba267377ee-20220630T175714Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).