On Thu, 22 Oct 2026 19:51:15 GMT, Alexander Zvegintsev <[email protected]> 
wrote:

>> Matthias Baesken has updated the pull request incrementally with one 
>> additional commit since the last revision:
>> 
>>   Check realloc result too, break out if malloc/realloc fails
>
> src/java.desktop/unix/native/common/java2d/x11/X11Renderer.c line 97:
> 
>> 95:         _pnts->x = X;                                                    
>>    \
>> 96:         _pnts->y = Y;                                                    
>>    \
>> 97:         (PTR)->npoints = _npnts + 1;                                     
>>    \
> 
> This change doesn't seem right to me.
> 
> If `malloc` fails, the `NULL` check only skips `memcpy`. The macro still 
> assigns `NULL` to `_pnts`, updates `maxpoints`, and writes the new point 
> through an invalid pointer, so a crash remains possible.
> 
> The `realloc` path has the same problem and also loses the pointer to the 
> original allocation on failure.
> 
> At minimum, we should store the result of `malloc`/`realloc` in a temporary 
> pointer and update the structure only on success. (and check if allocation 
> failure is handled safely by other code)

Yeah we should check the realloc result too.
I adjusted the coding, use now a temporary variable and break out in case of 
malloc/realloc failing.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/33513#discussion_r4357981003

Reply via email to