aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/stash.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/stash.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/stash.c')
-rw-r--r--builtin/stash.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/builtin/stash.c b/builtin/stash.c
index 7859bc0866..628d848a0b 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1018,13 +1018,14 @@ static int store_stash(int argc, const char **argv, const char *prefix)
int quiet = 0;
const char *stash_msg = NULL;
struct object_id obj;
- struct object_context dummy;
+ struct object_context dummy = {0};
struct option options[] = {
OPT__QUIET(&quiet, N_("be quiet")),
OPT_STRING('m', "message", &stash_msg, "message",
N_("stash message")),
OPT_END()
};
+ int ret;
argc = parse_options(argc, argv, prefix, options,
git_stash_store_usage,
@@ -1043,10 +1044,15 @@ static int store_stash(int argc, const char **argv, const char *prefix)
if (!quiet)
fprintf_ln(stderr, _("Cannot update %s with %s"),
ref_stash, argv[0]);
- return -1;
+ ret = -1;
+ goto out;
}
- return do_store_stash(&obj, stash_msg, quiet);
+ ret = do_store_stash(&obj, stash_msg, quiet);
+
+out:
+ object_context_release(&dummy);
+ return ret;
}
static void add_pathspecs(struct strvec *args,