From 244c27242f44e6b88e3a381c90bde08d134c274b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Wed, 16 Feb 2022 11:56:28 +0100 Subject: diff.[ch]: have diff_free() call clear_pathspec(opts.pathspec) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Have the diff_free() function call clear_pathspec(). Since the diff_flush() function calls this all its callers can be simplified to rely on it instead. When I added the diff_free() function in e900d494dcf (diff: add an API for deferred freeing, 2021-02-11) I simply missed this, or wasn't interested in it. Let's consolidate this now. This means that any future callers (and I've got revision.c in mind) that embed a "struct diff_options" can simply call diff_free() instead of needing know that it has an embedded pathspec. This does fix a bunch of leaks, but I can't mark any test here as passing under the SANITIZE=leak testing mode because in 886e1084d78 (builtin/: add UNLEAKs, 2017-10-01) an UNLEAK(rev) was added, which plasters over the memory leak. E.g. "t4011-diff-symlink.sh" would report fewer leaks with this fix, but because of the UNLEAK() reports none. I'll eventually loop around to removing that UNLEAK(rev) annotation as I'll fix deeper issues with the revisions API leaking. This is one small step on the way there, a new freeing function in revisions.c will want to call this diff_free(). Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Elijah Newren Signed-off-by: Junio C Hamano --- blame.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'blame.c') diff --git a/blame.c b/blame.c index 206c295660..401990726e 100644 --- a/blame.c +++ b/blame.c @@ -1403,7 +1403,6 @@ static struct blame_origin *find_origin(struct repository *r, } } diff_flush(&diff_opts); - clear_pathspec(&diff_opts.pathspec); return porigin; } @@ -1447,7 +1446,6 @@ static struct blame_origin *find_rename(struct repository *r, } } diff_flush(&diff_opts); - clear_pathspec(&diff_opts.pathspec); return porigin; } @@ -2328,7 +2326,6 @@ static void find_copy_in_parent(struct blame_scoreboard *sb, } while (unblamed); target->suspects = reverse_blame(leftover, NULL); diff_flush(&diff_opts); - clear_pathspec(&diff_opts.pathspec); } /* -- cgit v1.2.3