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

Fix memory leak in C extensions #419

Merged
merged 1 commit into from Aug 27, 2018

Conversation

JoostJM
Copy link
Collaborator

@JoostJM JoostJM commented Aug 27, 2018

Since C functionality is implemented for the calculation of the angles, texture matrix calculation returns a tuple of the matrix and the angles.
However, this uses Py_BuildValue with specifier "O", which increases the reference count, and thereby introduces a memory leak.

Fix this by replacing "O" by "N", which has the same effect for the returned values, but does not increase the reference count.

Moreover, the angles array is only needed for GLCM and GLRLM matrices. Therefore, only return the angles array in these 2 functions and free the array in the other functions.

fixes #417.

cc @Radiomics/developers, @JianJuly

Since C functionality is implemented for the calculation of the angles, texture matrix calculation returns a tuple of the matrix and the angles.
However, this uses Py_BuildValue with specifier "O", which increases the reference count, and thereby introduces a memory leak.

Fix this by replacing "O" by "N", which has the same effect for the returned values, but does not increase the reference count.

Moreover, the angles array is only needed for GLCM and GLRLM matrices. Therefore, only return the angles array in these 2 functions and free the array in the other functions.
@JoostJM JoostJM merged commit 917fadf into AIM-Harvard:master Aug 27, 2018
@JoostJM JoostJM added the bug label Aug 28, 2018
@JoostJM JoostJM deleted the bug-memory-leaks branch August 29, 2018 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory usage rapidly growing when repeatly invoke 'execute' function
1 participant