Skip to content

Commit 09320a8

Browse files
committed
Merge branch 'ab/hash-object-leakfix'
Trivial leakfix. * ab/hash-object-leakfix: hash-object: fix a trivial leak in --path
2 parents 5cc9522 + d17294a commit 09320a8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

builtin/hash-object.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
9292
int nongit = 0;
9393
unsigned flags = HASH_FORMAT_CHECK;
9494
const char *vpath = NULL;
95+
char *vpath_free = NULL;
9596
const struct option hash_object_options[] = {
9697
OPT_STRING('t', NULL, &type, N_("type"), N_("object type")),
9798
OPT_BIT('w', NULL, &flags, N_("write the object into the object database"),
@@ -114,8 +115,10 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
114115
else
115116
prefix = setup_git_directory_gently(&nongit);
116117

117-
if (vpath && prefix)
118-
vpath = prefix_filename(prefix, vpath);
118+
if (vpath && prefix) {
119+
vpath_free = prefix_filename(prefix, vpath);
120+
vpath = vpath_free;
121+
}
119122

120123
git_config(git_default_config, NULL);
121124

@@ -156,5 +159,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
156159
if (stdin_paths)
157160
hash_stdin_paths(type, no_filters, flags, literally);
158161

162+
free(vpath_free);
163+
159164
return 0;
160165
}

t/t1007-hash-object.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description="git hash-object"
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
echo_without_newline() {

0 commit comments

Comments
 (0)