fix bind/connect in devmode #2121
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
when bind was called with a string (i.e. usually), we encode to bytes before constructing the
char *to pass to libzmq. For code re-use purposes, this was consolidated in an inline function. But the problem with creating the bytes object withstr.encode()in the inline function is that it gets deallocated when the inline function returns. This has been safe because the actual memory doesn't get freed until the true function returns. However, devmode enablesPYTHONMALLOC=debug, which explicitly overwrites memory withPYMEM_DEADBYTEat dereference time (i.e. exit of the inline function), leading (rightly!) to EINVAL because the actual addr we are passing is"\xDD\xDD\xDD\xDD", not the user input.The fix is to return a Python bytes object from the inline function and hold its reference in the same scope as the pointer to its memory.
I'm not 100% sure why there wasn't an error or warning from Cython and/or C for this, but 🤷 .
closes #2093