]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mv: free the with_slash in check_dir_in_index()
authorShaoxuan Yuan <shaoxuan.yuan02@gmail.com>
Tue, 9 Aug 2022 12:09:04 +0000 (20:09 +0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Aug 2022 20:57:49 +0000 (13:57 -0700)
with_slash may be a malloc'd pointer, and when it is, free it.

Helped-by: Derrick Stolee <derrickstolee@github.com>
Helped-by: Victoria Dye <vdye@github.com>
Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mv.c

index 969f464f7d789b0fbda71394d4104f809538027c..c17df2a12f6b32a1766325907fd4b542c2c71704 100644 (file)
@@ -133,6 +133,7 @@ static int index_range_of_same_dir(const char *src, int length,
  */
 static int empty_dir_has_sparse_contents(const char *name)
 {
+       int ret = 0;
        const char *with_slash = add_slash(name);
        int length = strlen(with_slash);
 
@@ -142,14 +143,18 @@ static int empty_dir_has_sparse_contents(const char *name)
        if (pos < 0) {
                pos = -pos - 1;
                if (pos >= the_index.cache_nr)
-                       return 0;
+                       goto free_return;
                ce = active_cache[pos];
                if (strncmp(with_slash, ce->name, length))
-                       return 0;
+                       goto free_return;
                if (ce_skip_worktree(ce))
-                       return 1;
+                       ret = 1;
        }
-       return 0;
+
+free_return:
+       if (with_slash != name)
+               free((char *)with_slash);
+       return ret;
 }
 
 int cmd_mv(int argc, const char **argv, const char *prefix)