From patchwork Tue Mar 24 10:41:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 46235 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 863CA21596 for ; Tue, 24 Mar 2015 10:42:25 +0000 (UTC) Received: by labgm9 with SMTP id gm9sf31598788lab.1 for ; Tue, 24 Mar 2015 03:42:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=Cy3vv4tuQhEhrJ6YTi8GWFU+kT6EYXbtRsB/jitCZs0=; b=JuuGJX+Sx/yJOeRHUzdEBrpr3+/qL+I6AcXpuNb4szFDDaZmbIb6jQhWajCLS3J1lv gN4Qg0TO8TuARvPezszPDrgaH3uojaDt7TGVtIltjs6spQdxaaqihOqoCjCgw0GNz62M IeY9AeaX0l8lmzXi9TvtBvXMJF2/lIIGY7s23TKGE/Z+xqJx90WJPRPJHVMo0+jqIAt0 I7gCPwezUR9htx0vsGRfQFYce+Vsj5TYS+cNzKAUkOtzVrDuFNFZ8bqyBPwnQ2pJFe90 WxR9AG1hrnqwYA+qRXg0AChl74GdW5jEtioLqp3cm9xvjHhrVRGVgwo+U4haIXjrX1DE T5Tg== X-Gm-Message-State: ALoCoQnDqVvEdma4NRGLYVP/fWXbjDxOdTejWmUfNkDw57v+I+z7BYOUd/8grnKbW2F8HVp6F5sh X-Received: by 10.112.17.105 with SMTP id n9mr712336lbd.8.1427193744495; Tue, 24 Mar 2015 03:42:24 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.67 with SMTP id l3ls789521lae.93.gmail; Tue, 24 Mar 2015 03:42:24 -0700 (PDT) X-Received: by 10.112.181.231 with SMTP id dz7mr3044431lbc.47.1427193744154; Tue, 24 Mar 2015 03:42:24 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id zu3si2761175lbb.11.2015.03.24.03.42.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Mar 2015 03:42:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbbsy1 with SMTP id sy1so137789133lbb.1 for ; Tue, 24 Mar 2015 03:42:24 -0700 (PDT) X-Received: by 10.152.19.199 with SMTP id h7mr3365049lae.32.1427193744049; Tue, 24 Mar 2015 03:42:24 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.57.201 with SMTP id k9csp1363062lbq; Tue, 24 Mar 2015 03:42:23 -0700 (PDT) X-Received: by 10.55.41.80 with SMTP id p77mr7431021qkh.67.1427193741584; Tue, 24 Mar 2015 03:42:21 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id o31si3616537qko.37.2015.03.24.03.42.19 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 24 Mar 2015 03:42:21 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YaMHp-0005ZT-QO; Tue, 24 Mar 2015 10:42:17 +0000 Received: from mail-lb0-f171.google.com ([209.85.217.171]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YaMHg-0005Yt-5P for lng-odp@lists.linaro.org; Tue, 24 Mar 2015 10:42:08 +0000 Received: by lbbsy1 with SMTP id sy1so137783134lbb.1 for ; Tue, 24 Mar 2015 03:42:02 -0700 (PDT) X-Received: by 10.152.198.203 with SMTP id je11mr3043235lac.85.1427193722535; Tue, 24 Mar 2015 03:42:02 -0700 (PDT) Received: from cipriantemp.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id o8sm829010lal.24.2015.03.24.03.42.01 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Mar 2015 03:42:01 -0700 (PDT) From: Ciprian Barbu To: mike.holmes@linaro.org, lng-odp@lists.linaro.org Date: Tue, 24 Mar 2015 12:41:33 +0200 Message-Id: <1427193695-4932-2-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1427193695-4932-1-git-send-email-ciprian.barbu@linaro.org> References: <1427193695-4932-1-git-send-email-ciprian.barbu@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 1/3] example: odp_l2fwd: replace strtok_r with strtok and fix leaks X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ciprian.barbu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 The odp_l2fwd example leaks some strings allocated during parse_args. https://bugs.linaro.org/show_bug.cgi?id=1117 CID 56899: Resource leak (RESOURCE_LEAK) Signed-off-by: Ciprian Barbu --- example/l2fwd/odp_l2fwd.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c index d062a72..8ffb9dc 100644 --- a/example/l2fwd/odp_l2fwd.c +++ b/example/l2fwd/odp_l2fwd.c @@ -14,7 +14,6 @@ #define _POSIX_C_SOURCE 200112L #include -#include #include #include #include @@ -73,6 +72,7 @@ typedef struct { int if_count; /**< Number of interfaces to be used */ char **if_names; /**< Array of pointers to interface names */ int mode; /**< Packet IO mode */ + char *if_str; /**< Storage for interface names */ } appl_args_t; /** @@ -415,6 +415,8 @@ int main(int argc, char *argv[]) /* Master thread waits for other threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers); + free(gbl_args->appl.if_names); + free(gbl_args->appl.if_str); printf("Exit\n\n"); return 0; @@ -462,7 +464,7 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) { int opt; int long_index; - char *names, *str, *token, *save; + char *token; size_t len; int i; static struct option longopts[] = { @@ -495,19 +497,19 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) } len += 1; /* add room for '\0' */ - names = malloc(len); - if (names == NULL) { + appl_args->if_str = malloc(len); + if (appl_args->if_str == NULL) { usage(argv[0]); exit(EXIT_FAILURE); } /* count the number of tokens separated by ',' */ - strcpy(names, optarg); - for (str = names, i = 0;; str = NULL, i++) { - token = strtok_r(str, ",", &save); - if (token == NULL) - break; - } + strcpy(appl_args->if_str, optarg); + for (token = strtok(appl_args->if_str, ","), i = 0; + token != NULL; + token = strtok(NULL, ","), i++) + ; + appl_args->if_count = i; if (appl_args->if_count == 0) { @@ -520,11 +522,9 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) calloc(appl_args->if_count, sizeof(char *)); /* store the if names (reset names string) */ - strcpy(names, optarg); - for (str = names, i = 0;; str = NULL, i++) { - token = strtok_r(str, ",", &save); - if (token == NULL) - break; + strcpy(appl_args->if_str, optarg); + for (token = strtok(appl_args->if_str, ","), i = 0; + token != NULL; token = strtok(NULL, ","), i++) { appl_args->if_names[i] = token; } break;