From: "René Scharfe" <l.s.r@web.de>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
Derrick Stolee <stolee@gmail.com>,
Derrick Stolee <dstolee@microsoft.com>
Subject: [PATCH] commit-reach: plug minor memory leak after using is_descendant_of()
Date: Fri, 19 Jun 2020 15:13:46 +0200 [thread overview]
Message-ID: <ada13c16-d964-c6ee-80ac-626edbc5f52d@web.de> (raw)
ref_newer() 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.
Signed-off-by: René Scharfe <l.s.r@web.de>
---
We could allocate the commit_list on the stack, which would simplify such
glue code quite a bit. That would be dangerous in case is_descendant_of()
or some other function that is handed such a list tries to consume/free()
it. How can we be tell a function is safe to be given a stack-allocated
list? Perhaps by marking its argument as const. Or by converting all
functions to arrays.
commit-reach.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/commit-reach.c b/commit-reach.c
index 4ca7e706a1..6bba16e7b5 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -396,6 +396,7 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
struct object *o;
struct commit *old_commit, *new_commit;
struct commit_list *old_commit_list = NULL;
+ int ret;
/*
* Both new_commit and old_commit must be commit-ish and new_commit is descendant of
@@ -417,7 +418,9 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
return 0;
commit_list_insert(old_commit, &old_commit_list);
- return is_descendant_of(new_commit, old_commit_list);
+ ret = is_descendant_of(new_commit, old_commit_list);
+ free_commit_list(old_commit_list);
+ return ret;
}
/*
--
2.27.0
next reply other threads:[~2020-06-19 13:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-19 13:13 René Scharfe [this message]
2020-06-19 13:31 ` [PATCH] commit-reach: plug minor memory leak after using is_descendant_of() Jeff King
2020-06-19 14:07 ` Derrick Stolee
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=ada13c16-d964-c6ee-80ac-626edbc5f52d@web.de \
--to=l.s.r@web.de \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=stolee@gmail.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).