Re: [PATCH 6/7] init-db: silence template_dir leak when converting to absolute path
- From
Jeff King <peff@peff.net>
- Date
- Mar 8, 2021, 19:30 UTC
- Message-ID
- <YEZ7UXBScYozVfUS@coredump.intra.peff.net>
- In-Reply-To
- <6f81f3b2ab285f424c687072d4aef811a2471c24.1615228580.git.gitgitgadget@gmail.com>
On Mon, Mar 08, 2021 at 06:36:19PM +0000, Andrzej Hunt via GitGitGadget wrote:
Show 9 quoted lines
> 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