SNMP related memory leaks

From: Radu Greab <radu@dont-contact.us>
Date: Thu, 31 May 2001 21:30:52 +0300

Hello,

The patch below fixes another set of memory leaks:
- in snmpDecodePacket() the Community created in snmp_parse() was not
freed. Everyone querying squid through SNMP is affected.
- in snmpConstructResponse() the outbuf was not freed in all cases. It
seems more logical to me to move the xfree() call inside
snmpHandleUp(), just three lines down the xmalloc() call.

Thank you,
Radu Greab

Index: snmp_core.c
===================================================================
RCS file: /squid/squid/src/snmp_core.c,v
retrieving revision 1.45.2.2
diff -u -r1.45.2.2 snmp_core.c
--- snmp_core.c 2001/05/27 23:52:21 1.45.2.2
+++ snmp_core.c 2001/05/31 18:20:21
@@ -482,6 +482,7 @@
         snmp_rq->outbuf = xmalloc(snmp_rq->outlen = SNMP_REQUEST_SIZE);
         xmemcpy(&snmp_rq->from, &from, sizeof(struct sockaddr_in));
         snmpDecodePacket(snmp_rq);
+ xfree(rq->outbuf);
         xfree(snmp_rq);
     } else {
         debug(49, 1) ("snmpHandleUdp: FD %d recvfrom: %s\n", sock, xstrerror());
@@ -523,6 +524,8 @@
             inet_ntoa(rq->from.sin_addr));
         snmp_free_pdu(PDU);
     }
+ if (Community)
+ xfree(Community);
 }
 
 /*
@@ -545,7 +548,6 @@
         ret = snmp_build(&Session, RespPDU, rq->outbuf, &rq->outlen);
         sendto(rq->sock, rq->outbuf, rq->outlen, 0, (struct sockaddr *) &rq->from, sizeof(rq->from));
         snmp_free_pdu(RespPDU);
- xfree(rq->outbuf);
     }
 }
 
Received on Thu May 31 2001 - 12:31:04 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:02 MST