RFR: JDK-8304684: Memory leak in DirectivesParser::set_option_flag [v2]
Dean Long
dlong at openjdk.org
Thu Mar 23 23:41:28 UTC 2023
On Thu, 23 Mar 2023 23:27:52 GMT, Dean Long <dlong at openjdk.org> wrote:
>> I am very confused actually, `(set->*test)((void *)&s);` calls DirectiveSet::set_X. Looking at the code, it simply just stores the pointer? Is the DirectiveSet supposed to own the option? And if so, who is freeing it then? It doesn't look like cloning actually clones the underlying storage and the DirectiveSet destructor doesn't free it.
>>
>> So really DirectiveSet::~DirectiveSet should be freeing the string storage and DirectiveSet::set_X is taking ownership. Yeah?
>
> Right, the ownership of the string seems unclear. If we try to free the string storage in ~DirectiveSet I think it will result in a double free, because clone() appears to do a shallow copy.
Worse yet, it looks like the default value can point to the existing storage of the DisableIntrinsic and ControlIntrinsic global values, making it doubly hard to know if the storage can be freed, unless we get rid of simple = assignment and always allocate new memory when assigning the string values.
But why re-invent the wheel? Can't we use something like C++ std::string to manage the lifetimes for us?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13125#discussion_r1146978578
More information about the hotspot-compiler-dev
mailing list