From patchwork Wed Mar 25 11:58:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 46318 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6E9C521584 for ; Wed, 25 Mar 2015 11:58:47 +0000 (UTC) Received: by lbvn10 with SMTP id n10sf4251062lbv.1 for ; Wed, 25 Mar 2015 04:58:46 -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=OePojJ7iVSf0vUU0syPMzVHn7Oq1MYOG76smoEdtdqM=; b=TPm49Z6aGWsZum69C6wKWhvNM2iDVxGIT5Gvi/hxP5dvasTAFCkw0fBtBjn8OsqIB5 OcWk/h2JZHNBkWoyeJMf/WkC8TAiJ0tzptOoRQiw48htaxAyYo1HQqaY/4P3/Iwb6W8o dQrCxZHsEaEm2/lsgtz6Mll7myXyX5DfaF00oiLvjtAWBbzvkF9SHqsa2feGuKszu3T/ LWPhxBC80HUvYUNpEpJ+Vob1AtQIbfSmXJmqTXaLGXBS+3z/0+qcDmPZaIRD2IPa2jrb wCtFqT5vgEOmYTzH89soZm6pNg8pLhUZ/Uei5grwKgND2hT2u8Ge30LqPs2y6j2FjGfr WJJg== X-Gm-Message-State: ALoCoQnDoxykMrADp88RUAoh6iI1Qc/mkbAnAfy7NvHUrI4fxduVNDbUsROvilv4F60gW1NIJ9ao X-Received: by 10.152.19.67 with SMTP id c3mr1984943lae.7.1427284726420; Wed, 25 Mar 2015 04:58:46 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.227 with SMTP id b3ls78280lak.58.gmail; Wed, 25 Mar 2015 04:58:46 -0700 (PDT) X-Received: by 10.152.6.197 with SMTP id d5mr8137823laa.121.1427284726269; Wed, 25 Mar 2015 04:58:46 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id q1si1829708laj.84.2015.03.25.04.58.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Mar 2015 04:58:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbug6 with SMTP id ug6so15519124lbb.3 for ; Wed, 25 Mar 2015 04:58:46 -0700 (PDT) X-Received: by 10.112.162.232 with SMTP id yd8mr8035964lbb.41.1427284726175; Wed, 25 Mar 2015 04:58:46 -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 k9csp2039643lbq; Wed, 25 Mar 2015 04:58:45 -0700 (PDT) X-Received: by 10.52.251.75 with SMTP id zi11mr8638877vdc.70.1427284724643; Wed, 25 Mar 2015 04:58:44 -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 gv10si2913016vdc.64.2015.03.25.04.58.43 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 25 Mar 2015 04:58:44 -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 1YajxI-0000WD-TG; Wed, 25 Mar 2015 11:58:40 +0000 Received: from mail-lb0-f170.google.com ([209.85.217.170]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Yajx3-0000Uc-0I for lng-odp@lists.linaro.org; Wed, 25 Mar 2015 11:58:25 +0000 Received: by lbbug6 with SMTP id ug6so15511071lbb.3 for ; Wed, 25 Mar 2015 04:58:19 -0700 (PDT) X-Received: by 10.152.198.170 with SMTP id jd10mr8174577lac.60.1427284699137; Wed, 25 Mar 2015 04:58:19 -0700 (PDT) Received: from cipriantemp.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id je5sm530113lac.33.2015.03.25.04.58.17 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Mar 2015 04:58:18 -0700 (PDT) From: Ciprian Barbu To: mike.holmes@linaro.org, lng-odp@lists.linaro.org Date: Wed, 25 Mar 2015 13:58:02 +0200 Message-Id: <1427284682-5990-4-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1427284682-5990-1-git-send-email-ciprian.barbu@linaro.org> References: <1427284682-5990-1-git-send-email-ciprian.barbu@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv3 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.217.170 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 Reviewed-by: Mike Holmes --- example/generator/odp_generator.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 3870fd1..5c38ef4 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -51,6 +50,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 +703,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 +723,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 +766,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 +791,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;