Hi,
I'm sorry, I sent the patch against current unstable debian package, I rewrote 
it on the latest netsnmp svn trunk (rev 17207):

--- python/netsnmp/client_intf.c
+++ python/netsnmp/client_intf.c
@@ -1758,7 +1758,7 @@
   PyObject *varlist_iter;
   PyObject *varbind;
   PyObject *val_tuple = NULL;
-  PyObject *varbinds;
+  PyObject *varbinds = NULL;
   int varlist_len = 0;
   int varlist_ind;
   netsnmp_session *ss;
@@ -1983,14 +1983,13 @@
                          (len ? Py_BuildValue("s#", str_buf, len) :
                           Py_BuildValue("")));
             
-         Py_DECREF(varbind);
-
           } else {
            /* Return None for this variable. */
             _PyTuple_Resize(&val_tuple, result_count+1);
            PyTuple_SetItem(val_tuple, result_count++, Py_BuildValue(""));
            printf("netsnmp_walk: bad varbind (%d)\n", varlist_ind);
           }    
+         Py_XDECREF(varbind);
         }
         /* reuse the response as the next pdu to send */
         pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
@@ -2016,6 +2015,7 @@
   }
 
  done:
+  Py_XDECREF(varbinds);
   SAFE_FREE(oid_arr);
   return (val_tuple ? val_tuple : Py_BuildValue(""));
 }

Regards,

Gabriele Messineo

----------  Forwarded Message  ----------

Subject: python snmpwalk memory leak
Date: Friday 24 October 2008
From: Gabriele Messineo <[EMAIL PROTECTED]>
To: [email protected]

Hi,
I would like to re-open netsnmp Bug "[ 1868278 ] A bug in python useing 
netsnmp.snmpwalk".

That's because cited patch ( 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=497656 ) was addressing a 
seg fault. 

I did some tests in order to find the memory leak, I hope it can be avoided by 
applying the following patch:

--- python/netsnmp/client_intf.c
+++ python/netsnmp/client_intf.c
@@ -1778,7 +1778,7 @@
   PyObject *varlist;
   PyObject *varbind;
   PyObject *val_tuple = NULL;
-  PyObject *varbinds;
+  PyObject *varbinds = NULL;
   int varlist_len = 0;
   int varlist_ind;
   netsnmp_session *ss;
@@ -2003,14 +2003,13 @@
                          (len ? Py_BuildValue("s#", str_buf, len) :
                           Py_BuildValue("")));
             
-         Py_DECREF(varbind);
-
           } else {
            /* Return None for this variable. */
             _PyTuple_Resize(&val_tuple, result_count+1);
            PyTuple_SetItem(val_tuple, result_count++, Py_BuildValue(""));
            printf("netsnmp_walk: bad varbind (%d)\n", varlist_ind);
           }    
+         if(varbind) Py_DECREF(varbind);
         }
         /* reuse the response as the next pdu to send */
         pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
@@ -2036,6 +2035,7 @@
   }
 
  done:
+  if(varbinds) Py_DECREF(varbinds);
   SAFE_FREE(oid_arr);
   return (val_tuple ? val_tuple : Py_BuildValue(""));
 }

I'm not experienced with Python C API but I think the root cause was a missing 
Py_DECREF on some PyObjects. 

I suggest to test the patch to verify it is not breaking anything.

Thanks and Regards.

Gabriele Messineo

PS: I submitted a bug report in Debian toward the package libsnmp-python: 
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=503293

-------------------------------------------------------

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to