RFR: 6543126: Level.known can leak memory

Peter Levart peter.levart at gmail.com
Tue Aug 16 13:33:35 UTC 2016



On 08/16/2016 03:14 PM, Daniel Fuchs wrote:
> Hi Peter,
>
> On 16/08/16 13:52, Peter Levart wrote:
>> Ah, I see. Right. Of course, my bad.
>>
>> In that case, there is a possible race that could lead to exception 
>> here:
>>
>>  476             // add new Level.
>>  477             Level levelObject = new Level(name, x);
>>  478             return KnownLevel.findByValue(x,
>> KnownLevel::referent).get();
>>
>> ...between lines 477 and 478 and between lines 377 and 378, the newly
>> constructed Level object could already get GC-ed and so findByValue
>> could return an empty Optional.
>>
>> You should do something like:
>>
>> Level levelObject = new Level(name, x);
>> Level result = KnownLevel.findByValue(x, KnownLevel::referent).get();
>> Reference.reachabilityFence(levelObject);
>> return result;
>
> That's what I did in the very first version of the patch,
> but Chris commented that this was unnecessary because when
> level.getClass() == Level.class then levelObject == mirroredLevel.
> Chris found that using Reference.reachabilityFence(levelObject)
> just added more mystery - so I removed the statement.

Oh, yes. I missed Chris' comment. Perhaps just add a comment about that 
for posterity?

Regards, Peter

>
> best regards,
>
> -- daniel
>
>>
>>
>> Regards, Peter
>



More information about the core-libs-dev mailing list