From patchwork Sat May 14 23:08:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 622297 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 3r6j8S3Zl2z9t4k for ; Sun, 15 May 2016 09:08:55 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=ckur/UPF; dkim-atps=neutral Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id BBD541064D; Sat, 14 May 2016 16:08:54 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id E6B4710642 for ; Sat, 14 May 2016 16:08:53 -0700 (PDT) Received: from bar5.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 67B0F4200A9 for ; Sat, 14 May 2016 17:08:53 -0600 (MDT) X-ASG-Debug-ID: 1463267332-09eadd5dc4467140001-byXFYA Received: from mx3-pf1.cudamail.com ([192.168.14.2]) by bar5.cudamail.com with ESMTP id P0Rnn02mgkfApbWL (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 14 May 2016 17:08:52 -0600 (MDT) X-Barracuda-Envelope-From: u9012063@gmail.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.2 Received: from unknown (HELO mail-pa0-f66.google.com) (209.85.220.66) by mx3-pf1.cudamail.com with ESMTPS (RC4-SHA encrypted); 14 May 2016 23:08:52 -0000 Received-SPF: pass (mx3-pf1.cudamail.com: SPF record at _netblocks.google.com designates 209.85.220.66 as permitted sender) X-Barracuda-Apparent-Source-IP: 209.85.220.66 X-Barracuda-RBL-IP: 209.85.220.66 Received: by mail-pa0-f66.google.com with SMTP id xm6so673794pab.3 for ; Sat, 14 May 2016 16:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=pUbha5/m5Cs/UJufy9NAsJPMSJwn3Mkos9WkbQv+JPE=; b=ckur/UPFX98s7MjmTYowuPyy8RB53tMwm0IMfeBK3X43NW2RJY86uyEDWC6d0issNx sCTixhQsr20MCd2gcSxM6NitnLJP4gZdcCWQ9rCiF+0K3PpHJB8r7c1Qcpo3fHryar9z 4HmLbQuA85HMWUy0Yxh46DoY/20ZEtzgRq5d6/VVLGDBP1gX9jgl8j/mJ9r+4+rP5nud uZMLFYbx4urGytX3QdO//maM2RenYfuRmNVvPFIDLvmSOtwoV34yE0PFwuaM5VjmblM9 6bS9lAo491DhnTEur89UdvJEj4UWmTj0QEAU95AGal58Gq/Q+SproN355Q/aJUaVVW40 YA5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=pUbha5/m5Cs/UJufy9NAsJPMSJwn3Mkos9WkbQv+JPE=; b=WqAzXnQmEUWHa82225cHXwWud4YDUeOFqkCEUBudHVkGeyL1KUEsFw7yHsLHFjnhy4 qh/WYftxpsp2/5iEGKl/t+OL/J37QTco3yiTK0uybpLlXfUOj+It+qauOJZMi//J2Qzd 3oneMTw7KGLurgeJ2su+Rk4NUxwa2GAZwEM6Yh43XlOvBMEgQ3YRTbnja9NRNOKHksIf rjAfHGCCI4fPbaRTbq7Ouswk71q4HvxI6LC/3Cw33HCkd1Gje/Heb2Y97HY+5jiegqjw ihJiVBBpJ6avdf6tIJ6GvAU9+UZZBGUkHTmOzdY/eK2+XSHIUaU2bhe+zbFUF+59x92p U7yQ== X-Gm-Message-State: AOPr4FV1gUlF9JAPisQKKQgCb/cIjhcAd+W8sOC4B5ipqSiiIm84VktjkwS13nA0bmPKfw== X-Received: by 10.66.164.133 with SMTP id yq5mr34055485pab.107.1463267331988; Sat, 14 May 2016 16:08:51 -0700 (PDT) Received: from vm-dev.hsd1.ca.comcast.net. ([76.126.157.223]) by smtp.gmail.com with ESMTPSA id h88sm36889954pfd.10.2016.05.14.16.08.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 May 2016 16:08:51 -0700 (PDT) X-CudaMail-Envelope-Sender: u9012063@gmail.com From: William Tu To: dev@openvswitch.org X-CudaMail-MID: CM-V1-513015480 X-CudaMail-DTE: 051416 X-CudaMail-Originating-IP: 209.85.220.66 Date: Sat, 14 May 2016 16:08:42 -0700 X-ASG-Orig-Subj: [##CM-V1-513015480##][PATCHv2] ovn-nbctl: Fix memory leak reported by Valgrind. Message-Id: <1463267322-48468-1-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.5.0 X-GBUdb-Analysis: 0, 209.85.220.66, Ugly c=0.165853 p=-0.2 Source Normal X-MessageSniffer-Rules: 0-0-0-10165-c X-Barracuda-Connect: UNKNOWN[192.168.14.2] X-Barracuda-Start-Time: 1463267332 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using global scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_SC5_MJ1963, DKIM_SIGNED, MAILTO_TO_SPAM_ADDR, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.29583 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 DKIM_SIGNED Domain Keys Identified Mail: message has a signature 0.00 MAILTO_TO_SPAM_ADDR URI: Includes a link to a likely spammer email 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Subject: [ovs-dev] [PATCHv2] ovn-nbctl: Fix memory leak reported by Valgrind. 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" Definitely lost is reported by test 2026: ovn -- 3 HVs, 1 LS, 3 lports/HV. ds_put_char__ (dynamic-string.c:82) ds_put_char (dynamic-string.h:88) process_escape_args (process.c:103) main (ovn-nbctl.c:92) Another leak shown at ovn-sbctl.c with similar pattern. Signed-off-by: William Tu --- ovn/utilities/ovn-nbctl.c | 12 ++++++++---- ovn/utilities/ovn-sbctl.c | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 5bdf757..81864c9 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -67,7 +67,7 @@ static void parse_options(int argc, char *argv[], struct shash *local_options); static const char *nbctl_default_db(void); static void run_prerequisites(struct ctl_command[], size_t n_commands, struct ovsdb_idl *); -static void do_nbctl(const char *args, struct ctl_command *, size_t n, +static int do_nbctl(const char *args, struct ctl_command *, size_t n, struct ovsdb_idl *); int @@ -125,7 +125,10 @@ main(int argc, char *argv[]) if (seqno != ovsdb_idl_get_seqno(idl)) { seqno = ovsdb_idl_get_seqno(idl); - do_nbctl(args, commands, n_commands, idl); + if (do_nbctl(args, commands, n_commands, idl) == 0) { + free(args); + exit(EXIT_SUCCESS); + } } if (seqno == ovsdb_idl_get_seqno(idl)) { @@ -1157,7 +1160,7 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, } } -static void +static int do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl) { @@ -1296,7 +1299,7 @@ do_nbctl(const char *args, struct ctl_command *commands, size_t n_commands, ovsdb_idl_txn_destroy(txn); ovsdb_idl_destroy(idl); - exit(EXIT_SUCCESS); + return 0; try_again: /* Our transaction needs to be rerun, or a prerequisite was not met. Free @@ -1313,6 +1316,7 @@ try_again: free(c->table); } free(error); + return 1; } /* Frees the current transaction and the underlying IDL and then calls diff --git a/ovn/utilities/ovn-sbctl.c b/ovn/utilities/ovn-sbctl.c index a888333..2a07ce5 100644 --- a/ovn/utilities/ovn-sbctl.c +++ b/ovn/utilities/ovn-sbctl.c @@ -81,7 +81,7 @@ static void parse_options(int argc, char *argv[], struct shash *local_options); static const char *sbctl_default_db(void); static void run_prerequisites(struct ctl_command[], size_t n_commands, struct ovsdb_idl *); -static void do_sbctl(const char *args, struct ctl_command *, size_t n, +static int do_sbctl(const char *args, struct ctl_command *, size_t n, struct ovsdb_idl *); int @@ -138,7 +138,10 @@ main(int argc, char *argv[]) if (seqno != ovsdb_idl_get_seqno(idl)) { seqno = ovsdb_idl_get_seqno(idl); - do_sbctl(args, commands, n_commands, idl); + if (do_sbctl(args, commands, n_commands, idl) == 0) { + free(args); + exit(EXIT_SUCCESS); + } } if (seqno == ovsdb_idl_get_seqno(idl)) { @@ -835,7 +838,7 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands, } } -static void +static int do_sbctl(const char *args, struct ctl_command *commands, size_t n_commands, struct ovsdb_idl *idl) { @@ -974,7 +977,7 @@ do_sbctl(const char *args, struct ctl_command *commands, size_t n_commands, ovsdb_idl_txn_destroy(txn); ovsdb_idl_destroy(idl); - exit(EXIT_SUCCESS); + return 0; try_again: /* Our transaction needs to be rerun, or a prerequisite was not met. Free @@ -991,6 +994,7 @@ try_again: free(c->table); } free(error); + return 1; } /* Frees the current transaction and the underlying IDL and then calls