]> git.ipfire.org Git - thirdparty/git.git/commit - cache-tree.c
stop leaking lock structs in some simple cases
authorJeff King <peff@peff.net>
Tue, 5 Sep 2017 12:15:21 +0000 (08:15 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Sep 2017 08:19:54 +0000 (17:19 +0900)
commitbfffb48c5d520a5f181716b0330774a03cd3fa39
tree78488ee47fe26a6f3c1592c69402ba36f7661792
parentee4d8e455c0981269213eccfd788a9bb9adf77d9
stop leaking lock structs in some simple cases

Now that it's safe to declare a "struct lock_file" on the
stack, we can do so (and avoid an intentional leak). These
leaks were found by running t0000 and t0001 under valgrind
(though certainly other similar leaks exist and just don't
happen to be exercised by those tests).

Initializing the lock_file's inner tempfile with NULL is not
strictly necessary in these cases, but it's a good practice
to model.  It means that if we were to call a function like
rollback_lock_file() on a lock that was never taken in the
first place, it becomes a quiet noop (rather than undefined
behavior).

Likewise, it's always safe to rollback_lock_file() on a file
that has already been committed or deleted, since that
operation is a noop on an inactive lockfile (and that's why
the case in config.c can drop the "if (lock)" check as we
move away from using a pointer).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/reset.c
builtin/update-index.c
cache-tree.c
config.c