From 0bc05be08ffc3b7eed6544c7d637a4da67e16917 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Tue, 8 Jun 2010 23:10:08 -0400 Subject: [PATCH] Free blame view data when reloading view --- NEWS | 1 + tig.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/NEWS b/NEWS index 190e5dc..f46ee70 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,7 @@ Incompatibilities: Improvements: + - Plug several memory leaks. - Command line arguments are split into diff, revision, and file arguments and made available as %(diff-args), %(rev-args), and %(file-args). Diff view will limit diffs using %(file-args). diff --git a/tig.c b/tig.c index c963977..810e5e7 100644 --- a/tig.c +++ b/tig.c @@ -4911,6 +4911,7 @@ static bool blame_open(struct view *view) { char path[SIZEOF_STR]; + size_t i; if (!view->prev && *opt_prefix) { string_copy(path, opt_file); @@ -4928,6 +4929,24 @@ blame_open(struct view *view) return FALSE; } + /* First pass: remove multiple references to the same commit. */ + for (i = 0; i < view->lines; i++) { + struct blame *blame = view->line[i].data; + + if (blame->commit && blame->commit->id[0]) + blame->commit->id[0] = 0; + else + blame->commit = NULL; + } + + /* Second pass: free existing references. */ + for (i = 0; i < view->lines; i++) { + struct blame *blame = view->line[i].data; + + if (blame->commit) + free(blame->commit); + } + setup_update(view, opt_file); string_format(view->ref, "%s ...", opt_file); -- 2.30.2