From patchwork Wed Mar 11 13:52:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 45658 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id ED3BC214BF for ; Wed, 11 Mar 2015 13:52:50 +0000 (UTC) Received: by wghl18 with SMTP id l18sf6704318wgh.1 for ; Wed, 11 Mar 2015 06:52:50 -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=80+BJGEU3kD4KArsLPiHk5sL4rLG69HFICr37Bb+WFs=; b=aTfXMqdCs/GxLOGXBwbJFSj8PFeR/qQ9z6E9scdcPL6KG2lHXur2ZENetTU4sIhEH4 Bvf1wNyMPjKcZRVWMNipSB7daWnl94T3pwazAoBCw060o725QPC3ace0huNxhGWy06Zv 7FgQkya7AkhsBL3G6lo6eW+clKt9AEoNbRSXbqbTOHVsX568zd4+XRzpm4L3drJYM+dC AXf/5YqOlyOdALrV/8pWgDXgnC0uMwYHnhBctcmnZoEyn3XQ+2GVkeRPwMa4l0LdaMot KAFqJaiWzCA/ZEQyr3eATgbJAK1UZbgDwoRFwfM7d6VlWNpI9KsBJ9AdBGyeebIMiC9I AHmg== X-Gm-Message-State: ALoCoQm09jQkrZHNzPJw63bk/Sp+4Fv7vZX3EGe77/Kjvt+NxrpJm4q3Y368NtcFPByop08lxtfp X-Received: by 10.180.91.76 with SMTP id cc12mr5977952wib.7.1426081970212; Wed, 11 Mar 2015 06:52:50 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.14 with SMTP id t14ls159183laz.61.gmail; Wed, 11 Mar 2015 06:52:50 -0700 (PDT) X-Received: by 10.112.173.41 with SMTP id bh9mr34226691lbc.107.1426081970048; Wed, 11 Mar 2015 06:52:50 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id q3si2457968lag.1.2015.03.11.06.52.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 06:52:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by labgq15 with SMTP id gq15so8938498lab.1 for ; Wed, 11 Mar 2015 06:52:50 -0700 (PDT) X-Received: by 10.152.116.11 with SMTP id js11mr12817681lab.106.1426081969962; Wed, 11 Mar 2015 06:52:49 -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.35.133 with SMTP id h5csp2793188lbj; Wed, 11 Mar 2015 06:52:49 -0700 (PDT) X-Received: by 10.55.53.78 with SMTP id c75mr73599882qka.44.1426081968534; Wed, 11 Mar 2015 06:52:48 -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 q76si3460477qgq.44.2015.03.11.06.52.47 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 11 Mar 2015 06:52:48 -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 1YVh41-00022N-FD; Wed, 11 Mar 2015 13:52:45 +0000 Received: from mail-la0-f52.google.com ([209.85.215.52]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YVh3k-000215-TZ for lng-odp@lists.linaro.org; Wed, 11 Mar 2015 13:52:29 +0000 Received: by labge10 with SMTP id ge10so8887056lab.7 for ; Wed, 11 Mar 2015 06:52:23 -0700 (PDT) X-Received: by 10.112.123.99 with SMTP id lz3mr20846430lbb.48.1426081943308; Wed, 11 Mar 2015 06:52:23 -0700 (PDT) Received: from cipriantemp.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id kv10sm735552lac.23.2015.03.11.06.52.22 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Mar 2015 06:52:22 -0700 (PDT) From: Ciprian Barbu To: lng-odp@lists.linaro.org Date: Wed, 11 Mar 2015 15:52:04 +0200 Message-Id: <1426081924-12252-4-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1426081924-12252-1-git-send-email-ciprian.barbu@linaro.org> References: <1426081924-12252-1-git-send-email-ciprian.barbu@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 3/3] example: generator: 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.215.44 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_ipsec 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/generator/odp_generator.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 3870fd1..96f6cf7 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -51,6 +51,7 @@ typedef struct { int cpu_count; /**< system CPU count */ int if_count; /**< Number of interfaces to be used */ char **if_names; /**< Array of pointers to interface names */ + char *if_str; /**< Storage for interface names */ odp_pool_t pool; /**< Pool for packet IO */ odph_ethaddr_t srcmac; /**< src mac addr */ odph_ethaddr_t dstmac; /**< dest mac addr */ @@ -703,6 +704,9 @@ int main(int argc, char *argv[]) /* Master thread waits for other threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers); + + free(args->appl.if_names); + free(args->appl.if_str); printf("Exit\n\n"); return 0; @@ -720,7 +724,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[] = { @@ -763,19 +767,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) { @@ -788,11 +792,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;