Skip to content

Commit b305037

Browse files
author
Маслов Александр Александрович
committed
Added tp_dealloc method to fix memory leak
Signed-off-by: Маслов Александр Александрович <[email protected]>
1 parent d83a472 commit b305037

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

rosidl_generator_py/resource/_msg_base.c.em

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ offsetof(@(message.structure.namespaced_type.name)Base, _@(member.name)), 0, NUL
106106
{NULL} /* Sentinel */
107107
};
108108

109+
static void @(message.structure.namespaced_type.name)Base_dealloc(@(message.structure.namespaced_type.name)Base * self)
110+
{
111+
@[for member in message.structure.members]@
112+
@[ if not isinstance(member.type, BasicType)]@
113+
Py_XDECREF(self->_@(member.name));
114+
@[ end if]@
115+
@[end for]@
116+
Py_TYPE(self)->tp_free((PyObject *)self);
117+
}
118+
109119

110120
static PyTypeObject @(message.structure.namespaced_type.name)BaseType = {
111121
PyVarObject_HEAD_INIT(NULL, 0)
@@ -115,6 +125,7 @@ static PyTypeObject @(message.structure.namespaced_type.name)BaseType = {
115125
.tp_itemsize = 0,
116126
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
117127
.tp_new = PyType_GenericNew,
128+
.tp_dealloc = (destructor)@(message.structure.namespaced_type.name)Base_dealloc,
118129
.tp_members = @(message.structure.namespaced_type.name)Base_members,
119130
};
120131

0 commit comments

Comments
 (0)