From 837e34eba47f209a38fc9ab458bd103fd7515325 Mon Sep 17 00:00:00 2001 From: Martin Ågren Date: Thu, 5 Oct 2017 22:32:04 +0200 Subject: treewide: prefer lockfiles on the stack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no longer any need to allocate and leak a `struct lock_file`. The previous patch addressed an instance where we needed a minor tweak alongside the trivial changes. Deal with the remaining instances where we allocate and leak a struct within a single function. Change them to have the `struct lock_file` on the stack instead. These instances were identified by running `git grep "^\s*struct lock_file\s*\*"`. Signed-off-by: Martin Ågren Signed-off-by: Junio C Hamano --- builtin/diff.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'builtin/diff.c') diff --git a/builtin/diff.c b/builtin/diff.c index 7e3ebcea38..91995965d7 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -203,17 +203,16 @@ static int builtin_diff_combined(struct rev_info *revs, static void refresh_index_quietly(void) { - struct lock_file *lock_file; + struct lock_file lock_file = LOCK_INIT; int fd; - lock_file = xcalloc(1, sizeof(struct lock_file)); - fd = hold_locked_index(lock_file, 0); + fd = hold_locked_index(&lock_file, 0); if (fd < 0) return; discard_cache(); read_cache(); refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED); - update_index_if_able(&the_index, lock_file); + update_index_if_able(&the_index, &lock_file); } static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv) -- cgit v1.2.3