Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory allocation fixes in flatlaf-natives/flatlaf-natives-windows #591

Closed
johnplatts opened this issue Sep 19, 2022 · 3 comments
Closed
Milestone

Comments

@johnplatts
Copy link
Contributor

I noticed that the operator delete[] overload is missing (and should be added) to the flatlaf-natives/flatlaf-natives-windows/src/main/cpp/Runtime.cpp file as follows:

 void __cdecl operator delete[]( void* pv, size_t cb ) { 
 	if( pv != NULL ) 
 		::HeapFree( ::GetProcessHeap(), 0, pv ); 
 } 

The following line in flatlaf-natives/flatlaf-natives-windows/src/main/cpp/HWNDMap.cpp needs to be changed to delete[] table:

There is also undefined behavior in FlatWndProc::install, HWNDMap::HWNDMap, and HWNDMap::ensureCapacity if memory allocation fails.

@johnplatts
Copy link
Contributor Author

I have created a branch at https://github.com/johnplatts/FlatLaf_Win32_Native_Fix/tree/flatlaf_win32_native_fix that includes fixes to flatlaf-natives/flatlaf-natives-windows/src/main/cpp/ to fix the issues surrounding memory allocation failures and overflow in HWNDMap::ensureCapacity.

@DevCharly
Copy link
Collaborator

@johnplatts Thanks. I'll have a look at this in the next weeks.

@DevCharly
Copy link
Collaborator

@johnplatts thanks for the code.
I've changed it a little bit 😉
Sorry, but didn't like the extra methods in AllocRoutines.h. So, removed it.

I've also removed the integer overflow handling in HWNDMap because this will never occur.
The map is designed for a small amount of entries. (uses sorted table)
It is used only for shown Swing windows/frames/dialogs.
Usually there is only one main window and some temporary dialogs.
But there will be never 2147483647 windows. 😉

@DevCharly DevCharly added this to the 3.0 milestone Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants