Attached is a patch which addresses a few memory leak issues in the Python
Net-SNMP interface.

prior to the patch session creation leaked the session pointer...also within the
session, memory was allocated which was not freed by snmp_close()...both of
these issues were addressed as confirmed by valgrind.

==6346== LEAK SUMMARY:
==6346==    definitely lost: 0 bytes in 0 blocks.
==6346==      possibly lost: 0 bytes in 0 blocks.
==6346==    still reachable: 1,332,715 bytes in 8,499 blocks.
==6346==         suppressed: 0 bytes in 0 blocks.

The proposal is that these fixes be accepted prior to release.

thanks, Giovanni


Index: netsnmp/client.py
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/python/netsnmp/client.py,v
retrieving revision 1.6
diff -u -r1.6 client.py
--- netsnmp/client.py   27 Oct 2006 14:32:58 -0000      1.6
+++ netsnmp/client.py   3 Nov 2006 16:10:48 -0000
@@ -173,6 +173,10 @@
         res = client_intf.walk(self, varlist)
         return res

+    def __del__(self):
+        res = client_intf.delete_session(self)
+        return res
+
 import netsnmp

 def snmpget(*args, **kargs):
Index: netsnmp/client_intf.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/python/netsnmp/client_intf.c,v
retrieving revision 1.10
diff -u -r1.10 client_intf.c
--- netsnmp/client_intf.c       27 Oct 2006 14:47:10 -0000      1.10
+++ netsnmp/client_intf.c       3 Nov 2006 16:10:50 -0000
@@ -1258,7 +1258,7 @@
     goto end;
   }

-  session.peername = strdup(peer);
+  session.peername = peer;
   session.retries = retries; /* 5 */
   session.timeout = timeout; /* 1000000L */
   session.authenticator = NULL;
@@ -1291,10 +1291,8 @@
                             USM_AUTH_PROTO_SHA_LEN);
       session.securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN;
     } else if (!strcmp(auth_proto, "DEFAULT")) {
-      const oid *theoid =
-       get_default_authtype(&session.securityAuthProtoLen);
       session.securityAuthProto =
-       snmp_duplicate_objid(theoid, session.securityAuthProtoLen);
+       get_default_authtype(&session.securityAuthProtoLen);
     } else {
       if (verbose)
        printf("error:snmp_new_v3_session:Unsupported authentication
protocol(%s)\n", auth_proto);
@@ -1328,10 +1326,8 @@
                             USM_PRIV_PROTO_AES_LEN);
       session.securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN;
     } else if (!strcmp(priv_proto, "DEFAULT")) {
-      const oid *theoid =
-       get_default_privtype(&session.securityPrivProtoLen);
       session.securityPrivProto =
-       snmp_duplicate_objid(theoid, session.securityPrivProtoLen);
+       get_default_privtype(&session.securityPrivProtoLen);
     } else {
       if (verbose)
        printf("error:snmp_new_v3_session:Unsupported privacy protocol(%s)\n",
priv_proto);
@@ -1366,6 +1362,23 @@
 }

 static PyObject *
+netsnmp_delete_session(PyObject *self, PyObject *args)
+{
+  PyObject *session;
+  SnmpSession *ss = NULL;
+
+  if (!PyArg_ParseTuple(args, "O", &session)) {
+    return NULL;
+  }
+
+  ss = (SnmpSession *)py_netsnmp_attr_long(session, "sess_ptr");
+
+  snmp_close(ss);
+  return (Py_BuildValue(""));
+}
+
+
+static PyObject *
 netsnmp_get(PyObject *self, PyObject *args)
 {
   PyObject *session;
@@ -2396,6 +2409,8 @@
    "create a netsnmp session."},
   {"session_v3",  netsnmp_create_session_v3, METH_VARARGS,
    "create a netsnmp session."},
+  {"delete_session",  netsnmp_delete_session, METH_VARARGS,
+   "create a netsnmp session."},
   {"get",  netsnmp_get, METH_VARARGS,
    "perform an SNMP GET operation."},
   {"getnext",  netsnmp_getnext, METH_VARARGS,



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to