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 zero-copy allocation #517

Merged
merged 1 commit into from Mar 30, 2014
Merged

fix memory leak in zero-copy allocation #517

merged 1 commit into from Mar 30, 2014

Conversation

minrk
Copy link
Member

@minrk minrk commented Mar 26, 2014

two allocations were being made where only one made sense.

closes #486

@minrk
Copy link
Member Author

minrk commented Mar 26, 2014

test script (leaktest.py):

import zmq

ctx = zmq.Context.instance()
s = ctx.socket(zmq.PUB)
msg = b''

for i in range(100):
    s.send(msg, copy=False)

valgrind with: valgrind --tool=memcheck --leak-check=full python leaktest.py

valgrind before:

==19523== LEAK SUMMARY:
==19523==    definitely lost: 4,800 bytes in 200 blocks
==19523==    indirectly lost: 0 bytes in 0 blocks

valgrind after:

==19359== LEAK SUMMARY:
==19359==    definitely lost: 0 bytes in 0 blocks
==19359==    indirectly lost: 0 bytes in 0 blocks

I like losing 0 bytes!

@minrk
Copy link
Member Author

minrk commented Mar 26, 2014

This is segfaulting. More digging to do...

it appears to have been sensitive to
where in the function `malloc` is called.

Calling it later appears to fix the leak.

This is crazy.

Along the way, I cleaned it up to use one malloc of a struct with two ints,
and create the zmq_msg_t in the free_fn,
so if a leak returns it won't be so severe.
@minrk
Copy link
Member Author

minrk commented Mar 27, 2014

Okay, now this actually appears to work. The bug turns out to be some weird sensitivity to where in a function malloc is called in the Cython-generated code. That was a crazy day.

minrk added a commit that referenced this pull request Mar 30, 2014
fix memory leak in zero-copy allocation
@minrk minrk merged commit 2670c8c into zeromq:master Mar 30, 2014
@minrk minrk deleted the leaky branch March 30, 2014 02:53
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

Successfully merging this pull request may close these issues.

memory leak @ socket.recv_multipart(copy=False)
1 participant