-
Notifications
You must be signed in to change notification settings - Fork 36
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
New/delete vs malloc/free #76
Comments
looooo
added a commit
to looooo/pivy
that referenced
this issue
Feb 26, 2021
@wwmayer is this critical? Should it be included for the 0.19 bundles? |
No, it's not critical. As said with a normally built FreeCAD version everything works. It's just when building FreeCAD with the above compiler option there are checks at runtime to figure out many kind of memory issues. This option is mainly useful for developers. |
I think we can close this one. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In C++ you never should release memory with free() that was allocated with new() or release it with delete/delete[] that was allocated with malloc(). Although it works in most cases it's bad practice and there is no guarantee that it always works.
Recently I have built FreeCAD with the compiler option -fsanitize=address that is able to detect flaws like above. When running the unit tests there FreeCAD crashes and in the terminal a message appears like: alloc-dealloc-mismatch (malloc vs operator delete [])
I was able to reduce the crash to this little snippet:
In order to better locate the problem I have built pivy locally and then the utility directly pointed me to the line in the source code that causes the crash. It's the function _wrap_SoMFVec3f_setValues__SWIG_1 which contains this block:
As you can see the memory for temp4 is allocated with malloc, assigned to arg4 and this frees it with delete[] instead of free().
Since this is generated code I had a look at the file SoMFVec3f.i:
So to fix the problem the freearg must be fixed with:
The same fix must be applied to SoMFVec3d.i, SoMFVec2f.i and SoMFVec4f.i. Other classes are not affected as far as I can see.
The text was updated successfully, but these errors were encountered: