Thread (47 messages) 47 messages, 5 authors, 2021-03-21

Re: [PATCH 6/7] init-db: silence template_dir leak when converting to absolute path

flat view

From: Jeff King <hidden>
Date: 2021-03-08 19:31:24

On Mon, Mar 08, 2021 at 06:36:19PM +0000, Andrzej Hunt via GitGitGadget wrote:
template_dir starts off pointing to either argv or nothing. However if
the value supplied in argv is a relative path, absolute_pathdup() is
used to turn it into an absolute path. absolute_pathdup() allocates
a new string, and we then "leak" it when cmd_init_db() completes.

We don't bother to actually free the return value (instead we UNLEAK
it), because there's no significant advantage to doing so here.
Correctly freeing it would require more significant changes to code flow
which would be more noisy than beneficial.
Makes sense. The UNLEAK() could be conditional at the end of the
function (since it is OK to unleak a non-allocated variable, too), but I
like keeping it here with the allocation for clarity.

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help