-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Double free or corruption error when two instances of an OOT block that uses FFTW is called in GRC #6528
Comments
@graceyeung68 This is probably something that has to be fixed in the OOT block. There is nothing in the GNU Radio core that limits how many of a certain type of block can exist. There are many flowgraphs in use that have more than one of a certain block. You could post a link to your code on chat.gnuradio.org or the mailing list to see whether someone can help debug. We can leave this issue open for now in case the error is shown to be in GR. Please close otherwise. |
Thank you. So is the "new" function indicated above that returns the sptr for the class object automatically taken care of internally by python and I won't need to worry about free'ing or deleting any pointers that might be the cause of the error? Thank you. |
Smart pointers automatically delete the internal object when the refcount reaches 0. No explicit free is required. See Closing, since this is not a GNU Radio bug. |
@graceyeung68 yes, that should all happen under the hood correctly: Things are a bit more complicated than that. Python handles python objects, and in this case wrappers around these shared pointers which have been amended to have wrappers for all the methods and properties of the underlying class, It holds an instance of the shared pointer, which means that the moment the python wrapper is instantiated, that What a shared pointer is is really only, functionally: a pointer to a control block, and the actual object pointer (as allocated by the So, the pointer chain looks a bit like this:
The shared pointer holds a pointer to the control block, which holds the reference count. When you copy a shared pointer, that calls the shared pointer's copy constructor (or copy assignment operator), the control block pointer is copied, and the reference count is increased. That's the mechanism with which there is "shared" ownership. The pyobject actually holds a shared_ptr. That's not without challenges: Python's object life time is not as C++'s. In C++ you know exactly when a local object stops existing, in Python, objects which are no longer accessible (for example, because their single name now refers to something else) are garbage-collected at Python's own leisure. Now, when you tell your python program to actually copy that pyobject, what the wrapper should usually be doing is actually also make a copy of the held shared_ptr, which increases the reference count. So, if the original pyobject is garbage-collected, the reference count can't drop to zero. Noooow, if something somehow makes a copy of such a pyobject without actually calling the copy constructor of the shared pointer, but by simply actually copying the memory of the shared pointer, then you run into the problem where two things think they are the one reducing the reference counter below 1, and should call the object's destructor, and That should. Not. happen. It's not even clear it's what happens in your case; the double free problem might come from something else (that problem applies to everything that calls delete internally, that could be |
Thank you Marcus for the detailed explanation. I will give the debugger a try. One thing I do notice is the flowgraph crashes at different points in the code in each successive run after each crash giving a different error message such as: |
Backtracing shows the crash happens in an fftw3f library function used in the code. Is the fftw3f package compatible with GR? Thank you. (gdb) bt |
@willcode @marcusmueller Hi, I understand this issue has been closed. But from the previous comment, grc breaks during a call to fftw. I'd like to know if there is anything special that I should watch out for if I am simply trying to use fftw to perform a forward/backward transform. The double free error is occurring during a call to fftw. Thanks! |
What happened?
I have an out-of-tree block in c++ that runs fine in GRC but when I have two of them running simultaneously in a flowgraph, I am getting a "double free or corruption" error. I am not using any free() functions in my code. I use std::vector's in the code which should handle the dynamic memory allocation automatically. The only place I can see in the code is the definition of the make function that calls new to return an sptr as indicated below. What might be the cause of this error? Thank you.
System Information
OS: Ubuntu 20.04
GR Installation Method: apt?
GNU Radio Version
3.8 (maint-3.8)
Specific Version
3.8.1.0
Steps to Reproduce the Problem
Two instances of OOT block running simultaneously.
Relevant log output
double free or corruption (!prev)
The text was updated successfully, but these errors were encountered: