<AWT Dev> RFR: 8185739: Memory leak in BitmapUtil::BitmapToRgn

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

<AWT Dev> RFR: 8185739: Memory leak in BitmapUtil::BitmapToRgn

Philip Race
Bug: https://bugs.openjdk.java.net/browse/JDK-8185739
Webrev: http://cr.openjdk.java.net/~prr/8185739/

The complaint in the bug is about this code  ..
254 if (!IS_SAFE_SIZE_MUL(width / 2 + 1, height)) {
255 throw std::bad_alloc();

.. potentially leaking memory allocated and stored in "buf" if the
exception is thrown.

This is indeed a potential leak but
- the same location is also failing to release "hdc"
- it is unclear why this needs to throw bad_alloc instead of returning
NULL as
is happening elsewhere in this function and the only caller checks for NULL
and can handle it.
- There are two other return sites in the same function that may leak ..

I have updated all of these.


-phil.


Reply | Threaded
Open this post in threaded view
|

Re: <AWT Dev> RFR: 8185739: Memory leak in BitmapUtil::BitmapToRgn

Sergey Bylokhov
Looks fine.

On 06/11/2017 12:01, Phil Race wrote:

> Bug: https://bugs.openjdk.java.net/browse/JDK-8185739
> Webrev: http://cr.openjdk.java.net/~prr/8185739/
>
> The complaint in the bug is about this code  ..
> 254 if (!IS_SAFE_SIZE_MUL(width / 2 + 1, height)) {
> 255 throw std::bad_alloc();
>
> .. potentially leaking memory allocated and stored in "buf" if the
> exception is thrown.
>
> This is indeed a potential leak but
> - the same location is also failing to release "hdc"
> - it is unclear why this needs to throw bad_alloc instead of returning
> NULL as
> is happening elsewhere in this function and the only caller checks for NULL
> and can handle it.
> - There are two other return sites in the same function that may leak ..
>
> I have updated all of these.
>
>
> -phil.
>
>


--
Best regards, Sergey.
Reply | Threaded
Open this post in threaded view
|

Re: <AWT Dev> RFR: 8185739: Memory leak in BitmapUtil::BitmapToRgn

prasanta sadhukhan
In reply to this post by Philip Race
Hi Phil,

Since you are checking for buf value in line248 and doing cleanup,
shouldn't we do the same in line322 also in BlendCopy()?

Regards
Prasanta
On 11/7/2017 1:31 AM, Phil Race wrote:

> Bug: https://bugs.openjdk.java.net/browse/JDK-8185739
> Webrev: http://cr.openjdk.java.net/~prr/8185739/
>
> The complaint in the bug is about this code  ..
> 254 if (!IS_SAFE_SIZE_MUL(width / 2 + 1, height)) {
> 255 throw std::bad_alloc();
>
> .. potentially leaking memory allocated and stored in "buf" if the
> exception is thrown.
>
> This is indeed a potential leak but
> - the same location is also failing to release "hdc"
> - it is unclear why this needs to throw bad_alloc instead of returning
> NULL as
> is happening elsewhere in this function and the only caller checks for
> NULL
> and can handle it.
> - There are two other return sites in the same function that may leak ..
>
> I have updated all of these.
>
>
> -phil.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: <AWT Dev> RFR: 8185739: Memory leak in BitmapUtil::BitmapToRgn

Philip Race
Might as well ..

http://cr.openjdk.java.net/~prr/8185739.1

-phil.

On 11/06/2017 11:58 PM, Prasanta Sadhukhan wrote:

> Hi Phil,
>
> Since you are checking for buf value in line248 and doing cleanup,
> shouldn't we do the same in line322 also in BlendCopy()?
>
> Regards
> Prasanta
> On 11/7/2017 1:31 AM, Phil Race wrote:
>> Bug: https://bugs.openjdk.java.net/browse/JDK-8185739
>> Webrev: http://cr.openjdk.java.net/~prr/8185739/
>>
>> The complaint in the bug is about this code  ..
>> 254 if (!IS_SAFE_SIZE_MUL(width / 2 + 1, height)) {
>> 255 throw std::bad_alloc();
>>
>> .. potentially leaking memory allocated and stored in "buf" if the
>> exception is thrown.
>>
>> This is indeed a potential leak but
>> - the same location is also failing to release "hdc"
>> - it is unclear why this needs to throw bad_alloc instead of
>> returning NULL as
>> is happening elsewhere in this function and the only caller checks
>> for NULL
>> and can handle it.
>> - There are two other return sites in the same function that may leak ..
>>
>> I have updated all of these.
>>
>>
>> -phil.
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: <AWT Dev> RFR: 8185739: Memory leak in BitmapUtil::BitmapToRgn

prasanta sadhukhan
+1

Regards
Prasanta
On 11/8/2017 3:44 AM, Phil Race wrote:

> Might as well ..
>
> http://cr.openjdk.java.net/~prr/8185739.1
>
> -phil.
>
> On 11/06/2017 11:58 PM, Prasanta Sadhukhan wrote:
>> Hi Phil,
>>
>> Since you are checking for buf value in line248 and doing cleanup,
>> shouldn't we do the same in line322 also in BlendCopy()?
>>
>> Regards
>> Prasanta
>> On 11/7/2017 1:31 AM, Phil Race wrote:
>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8185739
>>> Webrev: http://cr.openjdk.java.net/~prr/8185739/
>>>
>>> The complaint in the bug is about this code  ..
>>> 254 if (!IS_SAFE_SIZE_MUL(width / 2 + 1, height)) {
>>> 255 throw std::bad_alloc();
>>>
>>> .. potentially leaking memory allocated and stored in "buf" if the
>>> exception is thrown.
>>>
>>> This is indeed a potential leak but
>>> - the same location is also failing to release "hdc"
>>> - it is unclear why this needs to throw bad_alloc instead of
>>> returning NULL as
>>> is happening elsewhere in this function and the only caller checks
>>> for NULL
>>> and can handle it.
>>> - There are two other return sites in the same function that may
>>> leak ..
>>>
>>> I have updated all of these.
>>>
>>>
>>> -phil.
>>>
>>>
>>
>