Re: [PATCH 13/22] builtin/fast-export: plug leaking tag names
- From
James Liu <james@jamesliu.io>
- Date
- Aug 7, 2024, 08:31 UTC
- Message-ID
- <D39JFO40F1FC.2Q22EY440N67N@jamesliu.io>
- In-Reply-To
- <64366155dee25209ab9c434016c5918d47d7e1d5.1722933642.git.ps@pks.im>
On Tue Aug 6, 2024 at 7:00 PM AEST, Patrick Steinhardt wrote:
Show 7 quoted lines
> Refactor the code to make the lists we put those names into duplicate > the memory. This allows us to properly free the string as required and > thus plugs the memory leak. > > While this requires us to allocate more data overall, it shouldn't be > all that bad given that the number of allocations corresponds with the > number of command line parameters, which typically aren't all that many.
Ahh so using the `STRING_LIST_INIT_DUP` initialiser means that every time we call `string_list_append()` on the list, we retain ownership of the string and the list gets its own copy.
That means we're able to free our own copy later on.