On Mon, 28 Nov 2022 03:23:01 GMT, Justin King <jck...@openjdk.org> wrote:

> Fix memory leaks by making `AddOption` unconditionally duplicate passed in 
> strings, taking ownership. Callers using dynamic memory free their storage 
> after calling `AddOption`. This ensures no memory is dropped on the floor. 
> This also removes the second argument to `AddOption` as it is unused and 
> shifts it into the source file.

If I read this correctly, the additional overhead for each option is a 
JLI_StringDup/JLI_MemFree, and a JLI_MemFree for the options that required 
JLI_MemAlloc. So while the ownership is clear, there is a lot of copying going 
on when there is a lot of XX options. It might be worth trying the other 
suggestion to have a parameter AddOption indicate if the option needs to be 
freed later (or a separate function). It does mean another array to track if 
the option should be freed but we can at least see how easy it is to maintain.

-------------

PR: https://git.openjdk.org/jdk/pull/11384

Reply via email to