summaryrefslogtreecommitdiff
path: root/builtin/reflog.c
diff options
context:
space:
mode:
authorMartin Ågren <martin.agren@gmail.com>2017-09-22 23:34:52 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-09-24 01:06:01 (GMT)
commitdcb572ab94f83a1a857d276fcebff5700077f2b7 (patch)
tree2ab4004547e87a0a54c3e403f746a0dd27c00744 /builtin/reflog.c
parentb2ccdf7fc15e866a883b706540055b5d05fb9aef (diff)
downloadgit-dcb572ab94f83a1a857d276fcebff5700077f2b7.zip
git-dcb572ab94f83a1a857d276fcebff5700077f2b7.tar.gz
git-dcb572ab94f83a1a857d276fcebff5700077f2b7.tar.bz2
object_array: use `object_array_clear()`, not `free()`
Instead of freeing `foo.objects` for an object array `foo` (sometimes conditionally), call `object_array_clear(&foo)`. This means we don't poke as much into the implementation, which is already a good thing, but also that we release the individual entries as well, thereby fixing at least one memory-leak (in diff-lib.c). If someone is holding on to a pointer to an element's `name` or `path`, that is now a dangling pointer, i.e., we'd be turning an unpleasant situation into an outright bug. To the best of my understanding no such long-term pointers are being taken. The way we handle `study` in builting/reflog.c still looks like it might leak. That will be addressed in the next commit. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/reflog.c')
-rw-r--r--builtin/reflog.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/builtin/reflog.c b/builtin/reflog.c
index e237d92..6b34f23 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -182,8 +182,8 @@ static int commit_is_complete(struct commit *commit)
found.objects[i].item->flags |= SEEN;
}
/* free object arrays */
- free(study.objects);
- free(found.objects);
+ object_array_clear(&study);
+ object_array_clear(&found);
return !is_incomplete;
}