git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] pull: plug minor memory leak after using is_descendant_of()
Date: Fri, 19 Jun 2020 15:14:19 +0200	[thread overview]
Message-ID: <52a584ee-ce2f-4416-3e3c-97ff15b5c346@web.de> (raw)

cmd_pull() builds a commit_list to pass a single potential ancestor to
is_descendant_of().  The latter leaves the list intact.  Release the
allocated memory after the call.

Leaking in cmd_*() isn't a big deal, but sets a bad example for other
users of is_descendant_of().

Signed-off-by: René Scharfe <l.s.r@web.de>
---
Patch generated with -U15 for easier review; only the pre-context is
interesting, though.  --function-context would add even more noise.
A --block-context option might be nice (include surrounding lines up to
and including the previous and next lines with lower indentation). :)
Or perhaps it's a sign that the function should be split up..

 builtin/pull.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/builtin/pull.c b/builtin/pull.c
index 00e5857a8d..8e6572d305 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -1019,30 +1019,31 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 		if (!autostash) {
 			struct commit_list *list = NULL;
 			struct commit *merge_head, *head;

 			head = lookup_commit_reference(the_repository,
 						       &orig_head);
 			commit_list_insert(head, &list);
 			merge_head = lookup_commit_reference(the_repository,
 							     &merge_heads.oid[0]);
 			if (is_descendant_of(merge_head, list)) {
 				/* we can fast-forward this without invoking rebase */
 				opt_ff = "--ff-only";
 				ran_ff = 1;
 				ret = run_merge();
 			}
+			free_commit_list(list);
 		}
 		if (!ran_ff)
 			ret = run_rebase(&curr_head, merge_heads.oid, &rebase_fork_point);

 		if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON ||
 			     recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND))
 			ret = rebase_submodules();

 		return ret;
 	} else {
 		int ret = run_merge();
 		if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON ||
 			     recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND))
 			ret = update_submodules();
 		return ret;
--
2.27.0

             reply	other threads:[~2020-06-19 13:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-19 13:14 René Scharfe [this message]
2020-06-19 13:35 ` [PATCH] pull: plug minor memory leak after using is_descendant_of() Jeff King

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=52a584ee-ce2f-4416-3e3c-97ff15b5c346@web.de \
    --to=l.s.r@web.de \
    --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).