Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:30301 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87709 invoked by uid 1010); 21 Jun 2007 06:46:11 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 87694 invoked from network); 21 Jun 2007 06:46:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jun 2007 06:46:11 -0000 Received: from [127.0.0.1] ([127.0.0.1:17535]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id D3/D5-32874-2BE1A764 for ; Thu, 21 Jun 2007 02:46:10 -0400 Authentication-Results: pb1.pair.com header.from=gustaf.gunnarsson@netadmin.se; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=gustaf.gunnarsson@netadmin.se; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain netadmin.se from 193.12.139.17 cause and error) X-PHP-List-Original-Sender: gustaf.gunnarsson@netadmin.se X-Host-Fingerprint: 193.12.139.17 unknown Linux 2.4/2.6 Received: from [193.12.139.17] ([193.12.139.17:39323] helo=mail.netadmin.se) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5C/F0-13585-FF5F8764 for ; Wed, 20 Jun 2007 05:40:18 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.netadmin.se (Postfix) with ESMTP id 94CBD7E1F; Wed, 20 Jun 2007 11:35:32 +0200 (CEST) Received: from mail.netadmin.se ([127.0.0.1]) by localhost (mail.netadmin.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 32447-06; Wed, 20 Jun 2007 11:35:29 +0200 (CEST) Received: from [10.254.6.3] (terminal-4.netadmin.nu [10.254.6.3]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.netadmin.se (Postfix) with ESMTP id 8D9147B59; Wed, 20 Jun 2007 11:35:29 +0200 (CEST) Message-ID: <4678F623.2080308@netadmin.se> Date: Wed, 20 Jun 2007 11:40:51 +0200 User-Agent: Thunderbird 1.5.0.12 (Windows/20070509) MIME-Version: 1.0 To: Rasmus Lerdorf , internals@lists.php.net Content-Type: multipart/mixed; boundary="------------010802030300080502080306" X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at netadmin.se Subject: [PATCH] ext/snmp/snmp.c memleaks From: gustaf.gunnarsson@netadmin.se (Gustaf Gunnarsson) --------------010802030300080502080306 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, the following patch fixes memory leaks in the snmp module. Diff against PHP 5.2 CVS branch. I'd also like to supply a patch later adding support for multiple set/get operations in one PDU. I'd like not to use php_snmp_internal() function for my new operations because I think that function is to complex and hard to audit. Is that acceptable? The new function definitions would be something like: array snmp_mget(string $version, string $hostname, mixed $authparameters, array $variables, [int $timeout, [int $retries]]) Where $authparameters may be (possibly) one of string array () array (snmpv3param1, snmpv3param2,....) $variables = array('var1','var2',...) Result will be returned in same fashion as realwalk(). and boolean snmp_mset(string $version, string $hostname, mixed $authparameters, array $variables, [int $timeout, [int $retries]]) $variables = array( array('oid','type','value'), array('oid2','type2','value2') ); //Gustaf --------------010802030300080502080306 Content-Type: text/plain; name="ext-snmp-snmp.c-memleakfix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ext-snmp-snmp.c-memleakfix.patch" Index: snmp.c =================================================================== RCS file: /repository/php-src/ext/snmp/snmp.c,v retrieving revision 1.106.2.2.2.4 diff -u -r1.106.2.2.2.4 snmp.c --- snmp.c 1 Jan 2007 09:36:06 -0000 1.106.2.2.2.4 +++ snmp.c 20 Jun 2007 09:18:49 -0000 @@ -421,6 +421,7 @@ name_length = MAX_OID_LEN; if (!snmp_parse_oid(objid, name, &name_length)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid object identifier: %s", objid); + snmp_free_pdu(pdu); snmp_close(ss); RETURN_FALSE; } @@ -434,6 +435,7 @@ sprint_objid(buf, name, name_length); #endif php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not add variable: %s %c %s", buf, type, value); + snmp_free_pdu(pdu); snmp_close(ss); RETURN_FALSE; } @@ -467,11 +469,13 @@ *return_value = *snmpval; zval_copy_ctor(return_value); zval_ptr_dtor(&snmpval); + snmp_free_pdu(response); snmp_close(ss); return; } else if (st == SNMP_CMD_GETNEXT) { *return_value = *snmpval; zval_copy_ctor(return_value); + snmp_free_pdu(response); snmp_close(ss); return; } else if (st == SNMP_CMD_WALK) { @@ -510,23 +514,28 @@ } if (st == SNMP_CMD_GET) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GET)) != NULL) { + snmp_free_pdu(response); goto retry; } } else if (st == SNMP_CMD_SET) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_SET)) != NULL) { + snmp_free_pdu(response); goto retry; } } else if (st == SNMP_CMD_GETNEXT) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GETNEXT)) != NULL) { + snmp_free_pdu(response); goto retry; } } else if (st >= SNMP_CMD_WALK) { /* Here we do walks. */ if ((pdu = snmp_fix_pdu(response, ((session->version == SNMP_VERSION_1) ? SNMP_MSG_GETNEXT : SNMP_MSG_GETBULK))) != NULL) { + snmp_free_pdu(response); goto retry; } } + snmp_free_pdu(response); snmp_close(ss); if (st == SNMP_CMD_WALK || st == SNMP_CMD_REALWALK) { zval_dtor(return_value); --------------010802030300080502080306--