summaryrefslogtreecommitdiff
path: root/tempfile.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-09-05 08:14:56 -0400
committerJunio C Hamano <gitster@pobox.com>2017-09-06 17:19:54 +0900
commit102cf7a6aa1f09177c09536a81dbaef44e13e038 (patch)
tree16663b48a6b271dc395fffc2c2cbe39d6e79afff /tempfile.c
parent6b935066960d19713d85e7bbebd442dd8d35e0c6 (diff)
downloadgit-102cf7a6aa1f09177c09536a81dbaef44e13e038.tar.gz
tempfile: release deactivated strbufs instead of resetting
When a tempfile is deactivated, we reset its strbuf to the empty string, which means we hold onto the memory for later reuse. Since we'd like to move to a system where tempfile structs can actually be freed, deactivating one should drop all resources it is currently using. And thus "release" rather than "reset" is the appropriate function to call. In theory the reset may have saved a malloc() when a tempfile (or a lockfile) is reused multiple times. But in practice this happened rarely. Most of our tempfiles are single-use, since in cases where we might actually use many (like ref locking) we xcalloc() a fresh one for each ref. In fact, we leak those locks (to appease the rule that tempfile storage can never be freed). Which means that using reset is actively hurting us: instead of leaking just the tempfile struct, we're leaking the extra heap chunk for the filename, too. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tempfile.c')
-rw-r--r--tempfile.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/tempfile.c b/tempfile.c
index 3348ad59dd..e655e28477 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -128,7 +128,7 @@ static void activate_tempfile(struct tempfile *tempfile)
static void deactivate_tempfile(struct tempfile *tempfile)
{
tempfile->active = 0;
- strbuf_reset(&tempfile->filename);
+ strbuf_release(&tempfile->filename);
}
/* Make sure errno contains a meaningful value on error */