On Thu, 5 Nov 2026 14:29:00 GMT, Matthias Baesken <[email protected]> wrote:

> We potentially leak a handle in case of failing malloc.
> 
> Additionally, GetFinalPathNameByHandleW can fail and return 0.  Then we 
> should free a newly allocated buffer.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

src/java.base/windows/native/libjava/canonicalize_md.c line 198:

> 196:             return finalPath;
> 197:         } else { // GetFinalPathNameByHandleW failed
> 198:             if (newFinalPath != NULL) free(newFinalPath);

I think it's better to put the error handling immediately after the 
`GetFinalPathNameByHandleW` call:


DWORD len = GetFinalPathNameByHandleW(h, finalPath, size, 0);
if (len == size) { // failed
   CloseHandle(h);
   return NULL;
}

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

PR Review Comment: https://git.openjdk.org/jdk/pull/33752#discussion_r4482370237

Reply via email to