From patchwork Wed Jun 28 00:35:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 781430 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wy3kK5hyWz9s0g for ; Wed, 28 Jun 2017 10:36:09 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 190B8AF8; Wed, 28 Jun 2017 00:35:39 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 092DD71F for ; Wed, 28 Jun 2017 00:35:37 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id A438C125 for ; Wed, 28 Jun 2017 00:35:35 +0000 (UTC) Received: from mfilter11-d.gandi.net (mfilter11-d.gandi.net [217.70.178.131]) by relay6-d.mail.gandi.net (Postfix) with ESMTP id 022A2FB882 for ; Wed, 28 Jun 2017 02:35:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter11-d.gandi.net Received: from relay6-d.mail.gandi.net ([IPv6:::ffff:217.70.183.198]) by mfilter11-d.gandi.net (mfilter11-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id wC-__dX8F6XZ for ; Wed, 28 Jun 2017 02:35:32 +0200 (CEST) X-Originating-IP: 208.91.1.34 Received: from sc9-mailhost2.vmware.com (unknown [208.91.1.34]) (Authenticated sender: jpettit@ovn.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id C10A7FB883 for ; Wed, 28 Jun 2017 02:35:31 +0200 (CEST) From: Justin Pettit To: dev@openvswitch.org Date: Tue, 27 Jun 2017 17:35:28 -0700 Message-Id: <1498610129-32658-1-git-send-email-jpettit@ovn.org> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 1/2] ofp-parse: Fix small memory leak when calling parse_ofp_meter_mod_str(). X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The function parse_ofp_meter_mod_str() allocates a buffer called 'bands', which parse_ofp_meter_mod_str__() then steals for the member 'mm->meter.bands'. Calling functions didn't free that stolen value and the comments for those function didn't indicate that was necessary. Found by valgrind. Signed-off-by: Justin Pettit --- lib/ofp-parse.c | 11 +++++++---- utilities/ovs-ofctl.c | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index 528b75b4f4e1..725fc41e063c 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -754,6 +754,8 @@ parse_ofp_packet_out_str(struct ofputil_packet_out *po, const char *str_, return error; } +/* Parse a string representation of a meter modification message to '*mm'. + * If successful, 'mm->meter.bands' must be free()d by the caller. */ static char * OVS_WARN_UNUSED_RESULT parse_ofp_meter_mod_str__(struct ofputil_meter_mod *mm, char *string, struct ofpbuf *bands, int command, @@ -795,6 +797,9 @@ parse_ofp_meter_mod_str__(struct ofputil_meter_mod *mm, char *string, mm->command = command; mm->meter.meter_id = 0; mm->meter.flags = 0; + mm->meter.n_bands = 0; + mm->meter.bands = NULL; + if (fields & F_BANDS) { band_str = strstr(string, "band"); if (!band_str) { @@ -945,9 +950,6 @@ parse_ofp_meter_mod_str__(struct ofputil_meter_mod *mm, char *string, } } } - } else { - mm->meter.n_bands = 0; - mm->meter.bands = NULL; } return NULL; @@ -957,7 +959,8 @@ parse_ofp_meter_mod_str__(struct ofputil_meter_mod *mm, char *string, * page) into 'mm' for sending the specified meter_mod 'command' to a switch. * * Returns NULL if successful, otherwise a malloc()'d string describing the - * error. The caller is responsible for freeing the returned string. */ + * error. The caller is responsible for freeing the returned string. + * If successful, 'mm->meter.bands' must be free()d by the caller. */ char * OVS_WARN_UNUSED_RESULT parse_ofp_meter_mod_str(struct ofputil_meter_mod *mm, const char *str_, int command, enum ofputil_protocol *usable_protocols) diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index ad862efe3e39..200ae9cb0078 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -3704,6 +3704,7 @@ ofctl_meter_mod__(const char *bridge, const char *str, int command) protocol = open_vconn_for_flow_mod(bridge, &vconn, usable_protocols); version = ofputil_protocol_to_ofp_version(protocol); transact_noreply(vconn, ofputil_encode_meter_mod(version, &mm)); + free(mm.meter.bands); vconn_close(vconn); } @@ -3732,6 +3733,7 @@ ofctl_meter_request__(const char *bridge, const char *str, version = ofputil_protocol_to_ofp_version(protocol); dump_transaction(vconn, ofputil_encode_meter_request(version, type, mm.meter.meter_id)); + free(mm.meter.bands); vconn_close(vconn); }