From patchwork Tue Mar 24 10:41:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 46237 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f199.google.com (mail-we0-f199.google.com [74.125.82.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EAF9721596 for ; Tue, 24 Mar 2015 10:42:31 +0000 (UTC) Received: by wesu56 with SMTP id u56sf31562848wes.2 for ; Tue, 24 Mar 2015 03:42:31 -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=ZlNBh/MBHvHlyU5Qf+5N56bXoctvAvXh/f45e0qEtjzVqk5Bm6SrPiBqAVOh3vGntk gT9cJ5zpzx0OxHwq6xvJZhH3WCOgG/wXN6iylmTpG/DdKi4LjaxsCzmw7bS3xXu3/7Kc Q78wOagGzg6VmSqABnURrw8I/uz4XGCtQf7jmvenGtZrGCHIdZT2dKgUy+VXRprFvtHx q5hFpO4Vk3wFd3fYvvkIRy/0gTsjnlLonQXCazU+2vTLQGHFvvoYbhBRveR6kxctPBky IoCRZv4/P1pEYA032czhSgChiSe5472IqPLkttbAdjYjrZtLnl2RdrEZ3inwIdUQLA8/ MgOA== X-Gm-Message-State: ALoCoQl9nMHXz/+taADd+BFpaOZpOMx0QDc8+UKLZkX9ln3Xtwd82TY6MDYgmjPgXy+kNvlzjGq6 X-Received: by 10.112.25.7 with SMTP id y7mr701735lbf.21.1427193751230; Tue, 24 Mar 2015 03:42:31 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.135 with SMTP id 7ls214989lam.8.gmail; Tue, 24 Mar 2015 03:42:30 -0700 (PDT) X-Received: by 10.112.210.230 with SMTP id mx6mr3271937lbc.64.1427193750940; Tue, 24 Mar 2015 03:42:30 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id er8si2752163lbc.23.2015.03.24.03.42.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Mar 2015 03:42:30 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by lagg8 with SMTP id g8so155961953lag.1 for ; Tue, 24 Mar 2015 03:42:30 -0700 (PDT) X-Received: by 10.152.206.70 with SMTP id lm6mr3216419lac.35.1427193750838; Tue, 24 Mar 2015 03:42:30 -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 k9csp1363114lbq; Tue, 24 Mar 2015 03:42:30 -0700 (PDT) X-Received: by 10.140.145.3 with SMTP id 3mr4715577qhr.43.1427193749506; Tue, 24 Mar 2015 03:42:29 -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 h198si3536175qhc.127.2015.03.24.03.42.28 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 24 Mar 2015 03:42:29 -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 1YaMHy-0005aP-ES; Tue, 24 Mar 2015 10:42:26 +0000 Received: from mail-la0-f42.google.com ([209.85.215.42]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YaMHi-0005Yv-63 for lng-odp@lists.linaro.org; Tue, 24 Mar 2015 10:42:10 +0000 Received: by laae1 with SMTP id e1so23790938laa.2 for ; Tue, 24 Mar 2015 03:42:04 -0700 (PDT) X-Received: by 10.112.144.41 with SMTP id sj9mr3179237lbb.3.1427193724571; Tue, 24 Mar 2015 03:42:04 -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.03 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Mar 2015 03:42:04 -0700 (PDT) From: Ciprian Barbu To: mike.holmes@linaro.org, lng-odp@lists.linaro.org Date: Tue, 24 Mar 2015 12:41:35 +0200 Message-Id: <1427193695-4932-4-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 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.215.46 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/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;