From patchwork Wed Mar 25 11:58:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 46317 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DF93F21584 for ; Wed, 25 Mar 2015 11:58:42 +0000 (UTC) Received: by wibbs8 with SMTP id bs8sf4973876wib.3 for ; Wed, 25 Mar 2015 04:58:41 -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=X8FJCegUf+Sw72BgnOmJ/POh7z3LZxvhTcYJk3RhXFK30vonxr/GT8Pyfxo/vVyCo0 ttlpwl9KQU53Z89W5vYACybxzlzDFLB/xjT/F1QBOw8qd8vjKLimzpKv+xOpralov3dU 83y/Ih0wdPTapfNZ1nz8TY7rC3igSqrEY/Z17Ij5ZyT3gyw5lgMoTQR/4TAYI19jYGdM 7/7+aaHD/kxtX78DtPhKuJ/+l8OSnO3Iy1INUdkD/jz5OnM5CThqjV/nECsRF+G4kfRx +16L4FJLcEnfqvNfbIcJoAzjJCXLA5Ss1YkV33UejzLgrKAfi6F1082I1BLof1So5CSX m6rA== X-Gm-Message-State: ALoCoQlM9uR1frn3xKM5+wN7PCTUOz8EeWHKeQcjuvYLfHMYeUmz7jwF6md6eJIDPzUyG0/SlcFO X-Received: by 10.152.163.99 with SMTP id yh3mr1989745lab.8.1427284721669; Wed, 25 Mar 2015 04:58:41 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.106 with SMTP id w10ls91956laz.62.gmail; Wed, 25 Mar 2015 04:58:41 -0700 (PDT) X-Received: by 10.152.42.193 with SMTP id q1mr7964588lal.92.1427284721366; Wed, 25 Mar 2015 04:58:41 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id g10si1814319lam.142.2015.03.25.04.58.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Mar 2015 04:58:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbcmq2 with SMTP id mq2so15620790lbc.0 for ; Wed, 25 Mar 2015 04:58:41 -0700 (PDT) X-Received: by 10.152.120.134 with SMTP id lc6mr8119389lab.72.1427284721278; Wed, 25 Mar 2015 04:58:41 -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 k9csp2039606lbq; Wed, 25 Mar 2015 04:58:40 -0700 (PDT) X-Received: by 10.52.151.227 with SMTP id ut3mr8531951vdb.85.1427284719642; Wed, 25 Mar 2015 04:58:39 -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 yg5si2953595vdb.6.2015.03.25.04.58.38 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 25 Mar 2015 04:58:39 -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 1YajxE-0000Vm-C5; Wed, 25 Mar 2015 11:58:36 +0000 Received: from mail-lb0-f182.google.com ([209.85.217.182]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Yajx1-0000UX-9W for lng-odp@lists.linaro.org; Wed, 25 Mar 2015 11:58:23 +0000 Received: by lbcgn8 with SMTP id gn8so15496766lbc.2 for ; Wed, 25 Mar 2015 04:58:17 -0700 (PDT) X-Received: by 10.152.36.133 with SMTP id q5mr1373677laj.35.1427284697760; Wed, 25 Mar 2015 04:58:17 -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.16 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Mar 2015 04:58:16 -0700 (PDT) From: Ciprian Barbu To: mike.holmes@linaro.org, lng-odp@lists.linaro.org Date: Wed, 25 Mar 2015 13:58:01 +0200 Message-Id: <1427284682-5990-3-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 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.182 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/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;