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 error when deallocating Python reaction rate wrappers #1030

Merged
merged 1 commit into from
May 8, 2021
Merged
Show file tree
Hide file tree
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 interfaces/cython/cantera/_cantera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -1130,10 +1130,12 @@ cdef class CustomReaction(Reaction):

cdef class Arrhenius:
cdef CxxArrhenius* rate
cdef cbool own_rate
cdef Reaction reaction # parent reaction, to prevent garbage collection

cdef class BlowersMasel:
cdef CxxBlowersMasel* rate
cdef cbool own_rate
cdef Reaction reaction

cdef class Falloff:
Expand Down
10 changes: 8 additions & 2 deletions interfaces/cython/cantera/reaction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,13 @@ cdef class Arrhenius:
def __cinit__(self, A=0, b=0, E=0, init=True):
if init:
self.rate = new CxxArrhenius(A, b, E / gas_constant)
self.own_rate = True
self.reaction = None
else:
self.own_rate = False

def __dealloc__(self):
if self.reaction is None:
if self.own_rate:
del self.rate

property pre_exponential_factor:
Expand Down Expand Up @@ -920,10 +923,13 @@ cdef class BlowersMasel:
def __cinit__(self, A=0, b=0, E0=0, w=0, init=True):
if init:
self.rate = new CxxBlowersMasel(A, b, E0 / gas_constant, w / gas_constant)
self.own_rate = True
self.reaction = None
else:
self.own_rate = False

def __dealloc__(self):
if self.reaction is None:
if self.own_rate:
del self.rate

property pre_exponential_factor:
Expand Down