From patchwork Wed Mar 11 13:52: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: 45656 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2E94A214BF for ; Wed, 11 Mar 2015 13:52:43 +0000 (UTC) Received: by lbiz11 with SMTP id z11sf6847034lbi.2 for ; Wed, 11 Mar 2015 06:52:42 -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=ZhNjz6CadPqWHAnmw20L9DTG5LHXvr6uEXlQLkGqONw=; b=NqdZS39eA1X2pRUa6qCY0F2jpH7gRpqfdcQKXI2ricdPaEGwWA3bz1VVMyzL9v4BYh yD/+JVgyPgWMRrntOWv06oWk2KL1G3SdhD/VUTSPFZPtYP8e+gXq3/nn929IFOv4Tq5B bfg20czCY9CEVr2Y+YlDAzKS7TM1pdUS0iFmMlYiH97i+AAl5r8nuFMbNjoEQvPoHJLx M7sJ1VsY+xBtCY45thI5+7iQMlpuZJu1JLS4JXLTZ7z4FEOzaV6QSMuSbfbgxBQG9guP mx+YUfEkbw+AYOl/InAew/ClTovm4u6ngHq6qGNulLVteTGSenKuLGbOr1pIg9gjRY2s v9Vg== X-Gm-Message-State: ALoCoQnS68bGaOiJ98QflXUHQX27wk+/tjfSADFaDGrl6P+hkqQjAU9LSwEbroaKhw/PpKsoHL51 X-Received: by 10.194.53.225 with SMTP id e1mr5526663wjp.4.1426081962134; Wed, 11 Mar 2015 06:52:42 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.45.6 with SMTP id i6ls161494lam.10.gmail; Wed, 11 Mar 2015 06:52:42 -0700 (PDT) X-Received: by 10.152.179.68 with SMTP id de4mr20492891lac.65.1426081962000; Wed, 11 Mar 2015 06:52:42 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id bf6si2416040lbc.57.2015.03.11.06.52.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 06:52:41 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbvn10 with SMTP id n10so8952071lbv.11 for ; Wed, 11 Mar 2015 06:52:41 -0700 (PDT) X-Received: by 10.152.116.65 with SMTP id ju1mr14520208lab.32.1426081961871; Wed, 11 Mar 2015 06:52: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.35.133 with SMTP id h5csp2793115lbj; Wed, 11 Mar 2015 06:52:40 -0700 (PDT) X-Received: by 10.140.165.209 with SMTP id l200mr49267490qhl.84.1426081959886; Wed, 11 Mar 2015 06:52: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 w9si3491277qcj.9.2015.03.11.06.52.38 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 11 Mar 2015 06:52: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 1YVh3s-00021a-Mh; Wed, 11 Mar 2015 13:52:36 +0000 Received: from mail-lb0-f169.google.com ([209.85.217.169]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YVh3j-000213-0b for lng-odp@lists.linaro.org; Wed, 11 Mar 2015 13:52:27 +0000 Received: by lbjb6 with SMTP id b6so8923757lbj.9 for ; Wed, 11 Mar 2015 06:52:21 -0700 (PDT) X-Received: by 10.152.21.136 with SMTP id v8mr35157854lae.64.1426081941338; Wed, 11 Mar 2015 06:52:21 -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.20 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Mar 2015 06:52:20 -0700 (PDT) From: Ciprian Barbu To: lng-odp@lists.linaro.org Date: Wed, 11 Mar 2015 15:52:02 +0200 Message-Id: <1426081924-12252-2-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 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.217.176 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 --- example/l2fwd/odp_l2fwd.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c index d062a72..a5f85c0 100644 --- a/example/l2fwd/odp_l2fwd.c +++ b/example/l2fwd/odp_l2fwd.c @@ -73,6 +73,7 @@ typedef struct { int if_count; /**< Number of interfaces to be used */ char **if_names; /**< Array of pointers to interface names */ int mode; /**< Packet IO mode */ + char *if_str; /**< Storage for interface names */ } appl_args_t; /** @@ -415,6 +416,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; @@ -462,7 +465,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[] = { @@ -495,19 +498,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) { @@ -520,11 +523,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;