From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by dpdk.org (Postfix) with ESMTP id BF98A8E6D for ; Tue, 17 Apr 2018 12:08:01 +0200 (CEST) Received: by mail-pf0-f195.google.com with SMTP id l27so11925758pfk.12 for ; Tue, 17 Apr 2018 03:08:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QYFnDxZ8xj1oXExGAgRq71LyR3EzdJ7lzioJncbwcqM=; b=FcHvqS+CfSamBiDHq71qlWNcsgr9fkVdIb3dyd01Ca9mvijawVv+9Rfv7J3wJuRRec 96fZk6nqR71OWW+ld1nCWFmo8HRDx+A1dsul0KJmet8Rb5zzu9C4vMhzXrzukyhnE32C KxYEV4g/bmGq/vw+0Lv7sw87xoc7H/qgja9+QOCmbo7Z+MSIP4BD5nEa8umIpQ8FR2X/ p3NMWdyOXOCfo0/GdCBTSKVyNEDroq2tYCSiLsTwJxhlHClWJsjYJ1xWnuntFPqZRO77 I4qRmiSqVp/Y2d+EPbnWB5Q7y1RkgvJc5K7bQQUO189MIxfe+EDcah8bCq0y65G+golS D9jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QYFnDxZ8xj1oXExGAgRq71LyR3EzdJ7lzioJncbwcqM=; b=LP4DchuOiICGHHBcdca1oGGk9nVEc7Jqm4c+ZhWgetWPCkdHDFl3Ik/g8Y6N6u+BEA RaHrhAXcq5QeKWuKLzYj8+ojeo9N2mHuPTNxJJGKwZShdHz+daJ6NfV+z4Ze5kyUfCeH vJck+M4Sui1Vz5p366p9EJ2fGFVUxt0tvjfXslwx2qlt0jsdv7Cm4RvNOsQqv2QUvmVf h3DsyjiYXXA08YJxvDM4SG5n16Q7vfm5vEjPV6Xa/QKIYCCAroSSpv4tre9bX9COsb66 aeehFfMtgxI84R+bJoAWJgckWz8mcaQd8OILH+k1dmLVn9dSy0aSURY8rWBWrqnTgX5q BUtg== X-Gm-Message-State: ALQs6tAB7w7r4IUzyUBrSMVRgfeeQg/Rv+7gmXY6lhHQpI+lMPO/Wyj8 Rv7SczWxhn8LuqKV+E0uLWRyhYV5 X-Google-Smtp-Source: AIpwx49F+yhyUenrvaobi459lWyeK/s7JFMdaDVt0nJvOaO/HV2cMrfC8oDG6ElaMi0dRdz4Ioyg5A== X-Received: by 10.99.47.4 with SMTP id v4mr1320449pgv.42.1523959680899; Tue, 17 Apr 2018 03:08:00 -0700 (PDT) Received: from localhost.localdomain (176.122.150.126.16clouds.com. [176.122.150.126]) by smtp.gmail.com with ESMTPSA id g26sm34698574pfk.173.2018.04.17.03.07.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Apr 2018 03:08:00 -0700 (PDT) From: Yangchao Zhou To: dev@dpdk.org Cc: thomas@monjalon.net, anatoly.burakov@intel.com Date: Tue, 17 Apr 2018 18:06:01 +0800 Message-Id: <1523959561-17400-1-git-send-email-zhouyates@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <6821483b-30f3-ac79-208c-406fb46685af@intel.com> References: <6821483b-30f3-ac79-208c-406fb46685af@intel.com> Subject: [dpdk-dev] [PATCH v2] mem: memory leaks of hubedir caused by strdup X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Apr 2018 10:08:02 -0000 Coverity issue: 272585 Fixes: cb97d93e9d3b ("mem: share hugepage info primary and secondary") Signed-off-by: Yangchao Zhou Acked-by: Anatoly Burakov --- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c index fb4b667..bf55334 100644 --- a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c +++ b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c @@ -169,8 +169,8 @@ return size; } -static const char * -get_hugepage_dir(uint64_t hugepage_sz) +static int +get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len) { enum proc_mount_fieldnames { DEVICE = 0, @@ -188,7 +188,7 @@ const char split_tok = ' '; char *splitstr[_FIELDNAME_MAX]; char buf[BUFSIZ]; - char *retval = NULL; + int retval = -1; FILE *fd = fopen(proc_mounts, "r"); if (fd == NULL) @@ -215,7 +215,8 @@ /* if no explicit page size, the default page size is compared */ if (pagesz_str == NULL){ if (hugepage_sz == default_size){ - retval = strdup(splitstr[MOUNTPT]); + snprintf(hugedir, len, "%s", splitstr[MOUNTPT]); + retval = 0; break; } } @@ -223,7 +224,8 @@ else { uint64_t pagesz = rte_str_to_size(&pagesz_str[pagesize_opt_len]); if (pagesz == hugepage_sz) { - retval = strdup(splitstr[MOUNTPT]); + snprintf(hugedir, len, "%s", splitstr[MOUNTPT]); + retval = 0; break; } } @@ -351,7 +353,6 @@ for (dirent = readdir(dir); dirent != NULL; dirent = readdir(dir)) { struct hugepage_info *hpi; - const char *hugedir; if (strncmp(dirent->d_name, dirent_start_text, dirent_start_len) != 0) @@ -363,10 +364,10 @@ hpi = &internal_config.hugepage_info[num_sizes]; hpi->hugepage_sz = rte_str_to_size(&dirent->d_name[dirent_start_len]); - hugedir = get_hugepage_dir(hpi->hugepage_sz); /* first, check if we have a mountpoint */ - if (hugedir == NULL) { + if (get_hugepage_dir(hpi->hugepage_sz, + hpi->hugedir, sizeof(hpi->hugedir)) < 0) { uint32_t num_pages; num_pages = get_num_hugepages(dirent->d_name); @@ -378,7 +379,6 @@ num_pages, hpi->hugepage_sz); continue; } - snprintf(hpi->hugedir, sizeof(hpi->hugedir), "%s", hugedir); /* try to obtain a writelock */ hpi->lock_descriptor = open(hpi->hugedir, O_RDONLY); -- 1.7.1