From patchwork Tue Mar 24 10:41:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 46236 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 98E3421596 for ; Tue, 24 Mar 2015 10:42:27 +0000 (UTC) Received: by lbdu14 with SMTP id u14sf15410749lbd.3 for ; Tue, 24 Mar 2015 03:42:26 -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=7p+Hm7PMV2VeXdwROCzeGZTA/wo6MVmiiBP6JGCFXxc=; b=m0ZeHk6uP63ExabYpajC2ZGKDQMfTWVuAtqSIBL5+B7zS4tLqoZt7Pg083dVDg5n+s hhsejFBS+v34NXhG5ty9YufUuOGcOZIbtihW6/DfTgrxnv0XXzkY6hxOe6XAxrYA3Wsf fpJgzl3eu0u/vEnnaBxDnusrkFYpIl7JRpLhuN+AzUwNTD9ZXEbC5VELzMQDGHHN8ur0 gdstDsRKf6ZWGwhGoUnp+jGFrPU+rzEuCj8wFy6p0BOUXZZMnrVlmbK8oZtP/h3WJbvM u8t9DzJGSWAj+lWwiCsWPGLBznIoTQC8sGg7Uk2bvtcSw9wAwAAYtLut3ZYPkoaSNHon DuUA== X-Gm-Message-State: ALoCoQkRXfbMAI03rdGHCO8onptiEVxXOqX4mu5RPK8wbq2CrD+pQItesc3pgke777TQj8AeYmo9 X-Received: by 10.112.148.10 with SMTP id to10mr732820lbb.18.1427193746638; Tue, 24 Mar 2015 03:42:26 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.136 with SMTP id e8ls877047lam.91.gmail; Tue, 24 Mar 2015 03:42:26 -0700 (PDT) X-Received: by 10.152.87.115 with SMTP id w19mr3253222laz.66.1427193746424; Tue, 24 Mar 2015 03:42:26 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id dt5si2681529lbc.111.2015.03.24.03.42.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Mar 2015 03:42:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbbug6 with SMTP id ug6so43308686lbb.3 for ; Tue, 24 Mar 2015 03:42:26 -0700 (PDT) X-Received: by 10.152.197.34 with SMTP id ir2mr3254473lac.36.1427193746291; Tue, 24 Mar 2015 03:42:26 -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 k9csp1363081lbq; Tue, 24 Mar 2015 03:42:25 -0700 (PDT) X-Received: by 10.55.33.41 with SMTP id h41mr7484571qkh.69.1427193744900; Tue, 24 Mar 2015 03:42:24 -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 v5si3625062qci.35.2015.03.24.03.42.23 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 24 Mar 2015 03:42:24 -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 1YaMHu-0005Zw-3l; Tue, 24 Mar 2015 10:42:22 +0000 Received: from mail-la0-f47.google.com ([209.85.215.47]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YaMHh-0005Yu-4A for lng-odp@lists.linaro.org; Tue, 24 Mar 2015 10:42:09 +0000 Received: by labto5 with SMTP id to5so48208566lab.0 for ; Tue, 24 Mar 2015 03:42:03 -0700 (PDT) X-Received: by 10.112.183.134 with SMTP id em6mr3200369lbc.52.1427193723553; Tue, 24 Mar 2015 03:42:03 -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.02 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Mar 2015 03:42:03 -0700 (PDT) From: Ciprian Barbu To: mike.holmes@linaro.org, lng-odp@lists.linaro.org Date: Tue, 24 Mar 2015 12:41:34 +0200 Message-Id: <1427193695-4932-3-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 2/3] example: odp_ipsec: 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.171 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/ipsec/odp_ipsec.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c index 82ed0cb..56e9aa8 100644 --- a/example/ipsec/odp_ipsec.c +++ b/example/ipsec/odp_ipsec.c @@ -14,7 +14,6 @@ /* enable strtok */ #define _POSIX_C_SOURCE 200112L #include -#include #include #include @@ -57,6 +56,7 @@ typedef struct { char **if_names; /**< Array of pointers to interface names */ crypto_api_mode_e mode; /**< Crypto API preferred mode */ odp_pool_t pool; /**< Buffer pool for packet IO */ + char *if_str; /**< Storage for interface names */ } appl_args_t; /** @@ -1274,6 +1274,8 @@ main(int argc, char *argv[]) odph_linux_pthread_join(thread_tbl, num_workers); } + free(args->appl.if_names); + free(args->appl.if_str); printf("Exit\n\n"); return 0; @@ -1290,10 +1292,7 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) { int opt; int long_index; - char *names; - char *str; char *token; - char *save; size_t len; int rc = 0; int i; @@ -1335,19 +1334,19 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) } len += 1; /* add room for '\0' */ - names = malloc(len); - if (NULL == names) { + 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 (NULL == token) - 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 (0 == appl_args->if_count) { @@ -1360,11 +1359,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 (NULL == token) - 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;