aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/log.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-06-11 11:19:59 +0200
committerJunio C Hamano <gitster@pobox.com>2024-06-11 13:15:05 -0700
commitf87c55c2647cf3aa0e6b5e45738facb6b62fe37c (patch)
tree1b098b88ceb32ecad516fbd68b93642a5488fd8e /builtin/log.c
parentbuiltin/rev-list: fix leaking bitmap index when calculating disk usage (diff)
downloadgit-f87c55c2647cf3aa0e6b5e45738facb6b62fe37c.tar.gz
git-f87c55c2647cf3aa0e6b5e45738facb6b62fe37c.zip
object-name: free leaking object contexts
While it is documented in `struct object_context::path` that this variable needs to be released by the caller, this fact is rather easy to miss given that we do not ever provide a function to release the object context. And of course, while some callers dutifully release the path, many others don't. Introduce a new `object_context_release()` function that releases the path. Convert callsites that used to free the path to use that new function and add missing calls to callsites that were leaking memory. Refactor those callsites as required to have a single return path, only. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/log.c')
-rw-r--r--builtin/log.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/builtin/log.c b/builtin/log.c
index 4e4b645a21..37ecb3ff8b 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -682,7 +682,7 @@ static void show_tagger(const char *buf, struct rev_info *rev)
static int show_blob_object(const struct object_id *oid, struct rev_info *rev, const char *obj_name)
{
struct object_id oidc;
- struct object_context obj_context;
+ struct object_context obj_context = {0};
char *buf;
unsigned long size;
@@ -698,7 +698,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
if (!obj_context.path ||
!textconv_object(the_repository, obj_context.path,
obj_context.mode, &oidc, 1, &buf, &size)) {
- free(obj_context.path);
+ object_context_release(&obj_context);
return stream_blob_to_fd(1, oid, NULL, 0);
}
@@ -706,7 +706,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
die(_("git show %s: bad file"), obj_name);
write_or_die(1, buf, size);
- free(obj_context.path);
+ object_context_release(&obj_context);
return 0;
}