]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hash-object: prefix_filename() returns allocated memory these days
authorJunio C Hamano <gitster@pobox.com>
Tue, 7 Sep 2021 22:10:22 +0000 (15:10 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Sep 2021 22:18:59 +0000 (15:18 -0700)
Back when a1be47e4 (hash-object: fix buffer reuse with --path in a
subdirectory, 2017-03-20) was written, the prefix_filename() helper
used a static piece of memory to the caller, making the caller
responsible for copying it, if it wants to keep it across another
call to the same function.  Two callers of the prefix_filename() in
hash-object were made to xstrdup() the value obtained from it.

But in the same series, when e4da43b1 (prefix_filename: return newly
allocated string, 2017-03-20) changed the rule to gave the caller
possession of the memory, we forgot to revert one of the xstrdup()
changes, allowing the returned value to leak.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/hash-object.c

index 640ef4ded595a3a21579a5630e04c3e6a412420d..084cba204ba28419a623e93b5f544be7a86b7b1a 100644 (file)
@@ -117,7 +117,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
                prefix = setup_git_directory_gently(&nongit);
 
        if (vpath && prefix)
-               vpath = xstrdup(prefix_filename(prefix, vpath));
+               vpath = prefix_filename(prefix, vpath);
 
        git_config(git_default_config, NULL);