-
Notifications
You must be signed in to change notification settings - Fork 85
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
C++ objects within structure allocated via calloc() #664
Comments
Would it be possible to just use a |
Most of the v2g_context needs to be zero initialised. A unique_ptr on it's own doesn't address this.
would have the problem of overwriting what any constructor would have done.
would be a pain to maintain. My suggestion would be to wrap the v2g_context in a class so that the C structures can be safely zero initialised and any C++ objects constructed as usual (and kept apart from the C structures/unions). As it stands it isn't a big problem since it looks like v2g_context is only constructed once and std::string is the only class used (at the moment). |
|
no idea - from reading that it implies that
my take on this - it might be fine. I've no idea. |
The example you're referring to uses a class |
Describe the bug
C++ objects should be created via new and removed via delete. This ensures that their constructors and destructors are properly called.
The v2g_context structure in EvseV2G is mostly pointers and basic types where use of calloc() to create the structure is fine.
However there are some std::string objects included that are not correctly constructed. When free() is called on the v2g_context pointer the strings are not destructed and hence there could be a memory leak.
One option would be to split the v2g_context structure into parts that can be managed via calloc/free and parts that require new/delete.
Starting points:
EVerest Domain
ISO15118
Affected EVerest Module
EvseV2G
To Reproduce
Present in the 2024.3.0 release
Anything else?
No response
The text was updated successfully, but these errors were encountered: