add: free leaked pathspec after add_files_to_cache()
authorJeff King <peff@peff.net>
Tue, 5 Sep 2017 13:04:10 +0000 (09:04 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Sep 2017 09:06:26 +0000 (18:06 +0900)
After run_diff_files, we throw away the rev_info struct,
including the pathspec that we copied into it, leaking the
memory. this is probably not a big deal in practice. We
usually only run this once per process, and the leak is
proportional to the pathspec list we're already holding in
memory.

But it's still a leak, and it pollutes leak-checker output,
making it harder to find important leaks.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/add.c
index c20548e4f545116c6e3bff75e59e953be603cc2a..ef625e3fb8b4f880f85e8a0283ecc18392ce19b6 100644 (file)
@@ -119,6 +119,7 @@ int add_files_to_cache(const char *prefix,
        rev.diffopt.flags |= DIFF_OPT_OVERRIDE_SUBMODULE_CONFIG;
        rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
        run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
+       clear_pathspec(&rev.prune_data);
        return !!data.add_errors;
 }