From patchwork Fri Aug 26 21:18:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 663249 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3sLYnm2tjcz9sD5 for ; Sat, 27 Aug 2016 07:19:08 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 9F79D10A44; Fri, 26 Aug 2016 14:19:07 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 82C5310A39 for ; Fri, 26 Aug 2016 14:19:06 -0700 (PDT) Received: from bar6.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 19A4D1622F8 for ; Fri, 26 Aug 2016 15:19:06 -0600 (MDT) X-ASG-Debug-ID: 1472246343-0b32371dea06a00001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar6.cudamail.com with ESMTP id lGpX7tNdU7jXGcs9 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 26 Aug 2016 15:19:03 -0600 (MDT) X-Barracuda-Envelope-From: blp@ovn.org X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO relay5-d.mail.gandi.net) (217.70.183.197) by mx1-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 26 Aug 2016 21:19:03 -0000 Received-SPF: pass (mx1-pf2.cudamail.com: SPF record at ovn.org designates 217.70.183.197 as permitted sender) X-Barracuda-Apparent-Source-IP: 217.70.183.197 X-Barracuda-RBL-IP: 217.70.183.197 Received: from mfilter18-d.gandi.net (mfilter18-d.gandi.net [217.70.178.146]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 7F56C41C08B; Fri, 26 Aug 2016 23:19:01 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter18-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter18-d.gandi.net (mfilter18-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id idXnWv9IyZoY; Fri, 26 Aug 2016 23:18:59 +0200 (CEST) X-Originating-IP: 208.91.2.3 Received: from sigabrt.benpfaff.org (unknown [208.91.2.3]) (Authenticated sender: blp@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 2E12841C074; Fri, 26 Aug 2016 23:18:58 +0200 (CEST) X-CudaMail-Envelope-Sender: blp@ovn.org From: Ben Pfaff To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E2-825063449 X-CudaMail-DTE: 082616 X-CudaMail-Originating-IP: 217.70.183.197 Date: Fri, 26 Aug 2016 14:18:53 -0700 X-ASG-Orig-Subj: [##CM-E2-825063449##][PATCH v2] ovsdb-idlc: Fix memory leaks in add and remove clause functions. Message-Id: <1472246333-5744-1-git-send-email-blp@ovn.org> X-Mailer: git-send-email 2.1.3 X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1472246343 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH v2] ovsdb-idlc: Fix memory leaks in add and remove clause functions. X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" Found by inspection. Signed-off-by: Ben Pfaff Acked-by: Amitabha Biswas > --- v1->v2: Fix some more leaks. (Thanks to Amitabha Biswas.) ovsdb/ovsdb-idlc.in | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index fc574b4..db4fa32 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -957,6 +957,8 @@ void function, &%(s)s_columns[%(S)s_COL_%(C)s], &datum); + + ovsdb_datum_destroy(&datum, &%(s)s_col_%(c)s.type); } """ % {'t': tableName, 'T': tableName.upper(), @@ -986,6 +988,7 @@ void 'args': ', '.join(['%(type)s%(name)s' % m for m in members])} print "{" print " struct ovsdb_datum datum;" + free = [] if type.n_min == 1 and type.n_max == 1: print " union ovsdb_atom key;" if type.value: @@ -1032,14 +1035,16 @@ void print " ovs_assert(inited);" print " datum.n = %s;" % nVar print " datum.keys = %s ? xmalloc(%s * sizeof *datum.keys) : NULL;" % (nVar, nVar) + free += ['datum.keys'] if type.value: print " datum.values = xmalloc(%s * sizeof *datum.values);" % nVar + free += ['datum.values'] else: print " datum.values = NULL;" print " for (i = 0; i < %s; i++) {" % nVar - print " " + type.key.copyCValue("datum.keys[i].%s" % type.key.type.to_string(), "%s[i]" % keyVar, refTable=False) + print " " + type.key.assign_c_value_casting_away_const("datum.keys[i].%s" % type.key.type.to_string(), "%s[i]" % keyVar, refTable=False) if type.value: - print " " + type.value.copyCValue("datum.values[i].%s" % type.value.type.to_string(), "%s[i]" % valueVar, refTable=False) + print " " + type.value.assign_c_value_casting_away_const("datum.values[i].%s" % type.value.type.to_string(), "%s[i]" % valueVar, refTable=False) print " }" if type.value: valueType = type.value.toAtomicType() @@ -1051,8 +1056,8 @@ void print""" ovsdb_idl_condition_add_clause(idl, &%(p)stable_classes[%(P)sTABLE_%(T)s], function, &%(s)s_columns[%(S)s_COL_%(C)s], - &datum); -}""" % {'t': tableName, + &datum);\ +""" % {'t': tableName, 'T': tableName.upper(), 'p': prefix, 'P': prefix.upper(), @@ -1060,6 +1065,9 @@ void 'S': structName.upper(), 'c': columnName, 'C': columnName.upper()} + for var in free: + print " free(%s);" % var + print "}" print """void %(s)s_add_clause_false(struct ovsdb_idl *idl) @@ -1123,6 +1131,8 @@ void function, &%(s)s_columns[%(S)s_COL_%(C)s], &datum); + + ovsdb_datum_destroy(&datum, &%(s)s_col_%(c)s.type); } """ % {'t': tableName, 'T': tableName.upper(), @@ -1152,6 +1162,7 @@ void 'args': ', '.join(['%(type)s%(name)s' % m for m in members])} print "{" print " struct ovsdb_datum datum;" + free = [] if type.n_min == 1 and type.n_max == 1: print " union ovsdb_atom key;" if type.value: @@ -1198,14 +1209,16 @@ void print " ovs_assert(inited);" print " datum.n = %s;" % nVar print " datum.keys = %s ? xmalloc(%s * sizeof *datum.keys) : NULL;" % (nVar, nVar) + free += ['datum.keys'] if type.value: + free += ['datum.values'] print " datum.values = xmalloc(%s * sizeof *datum.values);" % nVar else: print " datum.values = NULL;" print " for (i = 0; i < %s; i++) {" % nVar - print " " + type.key.copyCValue("datum.keys[i].%s" % type.key.type.to_string(), "%s[i]" % keyVar, refTable=False) + print " " + type.key.assign_c_value_casting_away_const("datum.keys[i].%s" % type.key.type.to_string(), "%s[i]" % keyVar, refTable=False) if type.value: - print " " + type.value.copyCValue("datum.values[i].%s" % type.value.type.to_string(), "%s[i]" % valueVar, refTable=False) + print " " + type.value.assign_c_value_casting_away_const("datum.values[i].%s" % type.value.type.to_string(), "%s[i]" % valueVar, refTable=False) print " }" if type.value: valueType = type.value.toAtomicType() @@ -1217,8 +1230,8 @@ void print""" ovsdb_idl_condition_remove_clause(idl, &%(p)stable_classes[%(P)sTABLE_%(T)s], function, &%(s)s_columns[%(S)s_COL_%(C)s], - &datum); -}""" % {'t': tableName, + &datum);\ +""" % {'t': tableName, 'T': tableName.upper(), 'p': prefix, 'P': prefix.upper(), @@ -1226,6 +1239,9 @@ void 'S': structName.upper(), 'c': columnName, 'C': columnName.upper()} + for var in free: + print " free(%s);" % var + print "}" print """void %(s)s_remove_clause_false(struct ovsdb_idl *idl)