Fix memory error when deallocating Python reaction rate wrappers #1030
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.
Using the value of member variables that are Python objects in
__dealloc__
is not reliable, because they may have already beendeleted by the time
__dealloc__
is called [Cython docs]. Instead, we need a C data member to check for whether or not the rate object owns the underlying C++ object and should delete it.The only way I've been able to trigger this bug is interactively in IPython, when trying to access members of the rate object with tab autocompletion. I think the reason for this is that this scenario ends up invoking the garbage collector, rather than having objects just get deleted when their reference counts go to zero, and that ends up behaving differently. I'm honestly surprised I didn't run into this before -- this is the way this has worked as long as this information has been accessible in Cython.
Changes proposed in this pull request
own_rate
to CythonArrhenius
andBlowersMasel
classes and use this when checking whether to delete the pointer to the corresponding C++ objects.Checklist
scons build
&scons test
) and unit tests address code coverage