Skip to content

Commit 102cf7a

Browse files
peffgitster
authored andcommitted
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>
1 parent 6b93506 commit 102cf7a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

tempfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static void activate_tempfile(struct tempfile *tempfile)
128128
static void deactivate_tempfile(struct tempfile *tempfile)
129129
{
130130
tempfile->active = 0;
131-
strbuf_reset(&tempfile->filename);
131+
strbuf_release(&tempfile->filename);
132132
}
133133

134134
/* Make sure errno contains a meaningful value on error */

0 commit comments

Comments
 (0)