From patchwork Wed Mar 25 11:58:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 46316 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4789C21584 for ; Wed, 25 Mar 2015 11:58:38 +0000 (UTC) Received: by wivz2 with SMTP id z2sf4968606wiv.1 for ; Wed, 25 Mar 2015 04:58:37 -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=w2uUsu49fza3eWj8cYnkAwEzoLfFm3BsG2auURtFf2g=; b=Ygugr3n0qZZVMXCGbIG58PST4J9ND2Ggg/sCV2e7t54VwSRDBfDlsz0LUz31JPKdNv ZMBsNGFdIdvUu3oPRm0Ts3QqJQHOwqdRR0EYFNRr/qK58kVlqIHL3ASoW2/Hvb8vWLIk +KKfyMkc332PshETAd5V6Vbfi3YBYRKi85yTD65gZKMDgBu1xSY09NdVleR6zVFwkXWm m4hhv9A3Sld7JvNTH78142Vbvyo8C6RV0vVny6XI5CIfwIskvTEgoT/T/7pNSXm8/w6/ hjdHoFq6b2jaSDRKsmwuKa0n9PynQhfPZn7sI4uMI8ywXq9O8Y3BBqHsrjJ3kAoxB6Wq qfiA== X-Gm-Message-State: ALoCoQnw7ImPNUZdLaHBrNTM7SvjUYYCoFzhPU8EaDNkr/gZAqwUfppO9tIWKBsShyZnH+yuVuFj X-Received: by 10.152.27.134 with SMTP id t6mr1990432lag.5.1427284717475; Wed, 25 Mar 2015 04:58:37 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.234.236 with SMTP id uh12ls94123lac.54.gmail; Wed, 25 Mar 2015 04:58:37 -0700 (PDT) X-Received: by 10.112.26.209 with SMTP id n17mr8156934lbg.84.1427284717203; Wed, 25 Mar 2015 04:58:37 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id kw12si1850839lac.3.2015.03.25.04.58.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Mar 2015 04:58:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by labto5 with SMTP id to5so17784353lab.0 for ; Wed, 25 Mar 2015 04:58:37 -0700 (PDT) X-Received: by 10.152.5.225 with SMTP id v1mr8032637lav.76.1427284716944; Wed, 25 Mar 2015 04:58:36 -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 k9csp2039572lbq; Wed, 25 Mar 2015 04:58:36 -0700 (PDT) X-Received: by 10.53.9.100 with SMTP id dr4mr8695112vdd.6.1427284715264; Wed, 25 Mar 2015 04:58:35 -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 on2si2878831vdb.106.2015.03.25.04.58.33 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 25 Mar 2015 04:58:35 -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 1Yajx9-0000VO-Ri; Wed, 25 Mar 2015 11:58:31 +0000 Received: from mail-la0-f44.google.com ([209.85.215.44]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Yajx0-0000UW-Vr for lng-odp@lists.linaro.org; Wed, 25 Mar 2015 11:58:23 +0000 Received: by lagg8 with SMTP id g8so17659571lag.1 for ; Wed, 25 Mar 2015 04:58:16 -0700 (PDT) X-Received: by 10.152.44.225 with SMTP id h1mr7795826lam.99.1427284696452; Wed, 25 Mar 2015 04:58:16 -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.15 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 25 Mar 2015 04:58:15 -0700 (PDT) From: Ciprian Barbu To: mike.holmes@linaro.org, lng-odp@lists.linaro.org Date: Wed, 25 Mar 2015 13:58:00 +0200 Message-Id: <1427284682-5990-2-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 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.215.45 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 Reviewed-by: Mike Holmes --- v3: - rebased on top of latest 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 a6ce478..4a49008 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 @@ -75,6 +74,7 @@ typedef struct { int mode; /**< Packet IO mode */ int time; /**< Time in seconds to run. */ int accuracy; /**< Number of seconds to get and print statistics */ + char *if_str; /**< Storage for interface names */ } appl_args_t; static int exit_threads; /**< Break workers loop if set to 1 */ @@ -465,6 +465,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; @@ -512,7 +514,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[] = { @@ -555,19 +557,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) { @@ -580,11 +582,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;