jiridanek commented on a change in pull request #1032:
URL: https://github.com/apache/qpid-dispatch/pull/1032#discussion_r576074879



##########
File path: src/python_embedded.c
##########
@@ -718,10 +719,24 @@ static int IoAdapter_init(IoAdapter *self, PyObject 
*args, PyObject *kwds)
     return 0;
 }
 
+// visit all members which may conceivably participate in reference cycles
+static int IoAdapter_traverse(IoAdapter* self, visitproc visit, void *arg)
+{
+    Py_VISIT(self->handler);
+    return 0;
+}
+
+static int IoAdapter_clear(IoAdapter* self)
+{
+    Py_CLEAR(self->handler);
+    return 0;
+}
+

Review comment:
       This deals with the following leak, which was previously suppressed, 
because it involves Python in the stacktrace
   
   ```
   9: Direct leak of 56 byte(s) in 1 object(s) allocated from:
   9:     #0 0x7f78a3606e8f in __interceptor_malloc 
(/nix/store/g40sl3zh3nv52vj0mrl4iki5iphh5ika-gcc-10.2.0-lib/lib/libasan.so.6+0xace8f)
   9:     #1 0x7f78a2d64afb in qd_malloc ../include/qpid/dispatch/ctools.h:229
   9:     #2 0x7f78a2d657da in qdr_core_subscribe 
../src/router_core/route_tables.c:149
   9:     #3 0x7f78a2c83072 in IoAdapter_init ../src/python_embedded.c:711
   9:     #4 0x7f78a2353a6c in type_call 
(/nix/store/r85nxfnwiv45nbmf5yb60jj8ajim4m7w-python3-3.8.5/lib/libpython3.8.so.1.0+0x165a6c)
   ```
   
   The problem is in
   
   ```python
   class Agent:
       ...
       def activate(self, address):
           ...
           self.io = IoAdapter(self.receive, address, 'L', '0', 
TREATMENT_ANYCAST_CLOSEST)
   ```
   
   IoAdapter refers to Agent (through the bound method reference to 
self.receive) and Agent refers to IoAdapter (through property self.io). Since 
IoAdapter is implemented in C and does not support Python's GC, there is no way 
to break the cycle.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to