Ticket #270 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

CEnumDefNode leaks memory during construction

Reported by: dagss Owned by:
Priority: major Milestone: 0.11.1
Component: Memory Leak Keywords:
Cc:

Description

It's only int literals, but a leak is a leak.

Change History

Changed 4 years ago by dagss

This only applies to public enums though.

Changed 4 years ago by dagss

I think the following is a fix, but I don't know how to use public enums and so I cannot produce a test case. Is the following testcase supposed to work?

"""
Just make sure the refnanny is run and that no leaks
are reported.

>>> Red
10
"""

cdef public enum:
    Red = 10
    Green = 12
    Blue = 4322123

Patch:

diff -r 3aa127500ce9 Cython/Compiler/Nodes.py
--- a/Cython/Compiler/Nodes.py  Tue Mar 31 23:07:13 2009 +0200
+++ b/Cython/Compiler/Nodes.py  Tue Mar 31 23:25:54 2009 +0200
@@ -915,12 +915,13 @@ class CEnumDefNode(StatNode):
                         self.temp,
                         item.cname,
                         code.error_goto_if_null(self.temp, item.pos)))
+                code.put_gotref(self.temp)
                 code.putln('if (__Pyx_SetAttrString(%s, "%s", %s) < 0) %s' % (
                         Naming.module_cname, 
                         item.name, 
                         self.temp,
                         code.error_goto(item.pos)))
-                code.putln("%s = 0;" % self.temp)
+                code.put_decref_clear(self.temp, PyrexTypes.py_object_type)
 
 
 class CEnumDefItemNode(StatNode):

Changed 4 years ago by robertwb

  • status changed from new to closed
  • resolution set to fixed

Yes, that is the idea. I merged your patch.

Note: See TracTickets for help on using tickets.