8000 Fix memory leak in concatenate. by cianci · Pull Request #373 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Fix memory leak in concatenate. #373

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

Merged
merged 1 commit into from
Aug 4, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions numpy/core/src/multiarray/multiarraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ PyArray_Concatenate(PyObject *op, int axis)
for (iarrays = 0; iarrays < narrays; ++iarrays) {
Py_DECREF(arrays[iarrays]);
}
PyArray_free(arrays);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PyDataMem_* functions might be preferable here, might also be a bit of overkill...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm certainly no expert, but I know a memory leak when I see one, and I attempted to plug it in the simplest/quickest/least-invasive way I could find. I really have no preference as to how it gets fixed, as long as it gets fixed (preferably soon). [grin]

Do you have (or could you quickly throw together) an alternative patch that uses the method you propose?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the patch looks fine, but there was a recent commit that allows tracking memory usage with the PyDataMem_NEW/PyDataMem_FREE. functions, so I'd like some input from the patch author as to what all memory we should be tracking and what we shouldn't worry about. You can see the routines themselves as they are in the same code unit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PyDataMem_* functions are for allocating array data. This is allocating a c-array of pointers to ArrayObjects. I don't think it would be helpful to track this in the same way.

PyArray_malloc/free seem like the right approach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that optionally uses the Python allocation. My own preference would probably be malloc/free if we don't want to track memory usage in these things.


return (PyObject *)ret;

Expand All @@ -610,6 +611,7 @@ PyArray_Concatenate(PyObject *op, int axis)
for (iarrays = 0; iarrays < narrays; ++iarrays) {
Py_DECREF(arrays[iarrays]);
}
PyArray_free(arrays);

return NULL;
}
Expand Down
0