From: Yangchao Zhou <zhouyates@gmail.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net
Subject: [dpdk-dev] [PATCH] mem: memory leaks of hubedir caused by strdup
Date: Tue, 17 Apr 2018 17:43:16 +0800 [thread overview]
Message-ID: <1523958196-6408-1-git-send-email-zhouyates@gmail.com> (raw)
Fixes: cb97d93e9d3bb5607681085d20acaca1aa16deb1("mem: share hugepage info primary and secondary")
Signed-off-by: Yangchao Zhou <zhouyates@gmail.com>
---
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
next reply other threads:[~2018-04-17 9:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-17 9:43 Yangchao Zhou [this message]
2018-04-17 9:57 ` Burakov, Anatoly
2018-04-17 10:06 ` [dpdk-dev] [PATCH v2] " Yangchao Zhou
2018-04-17 10:24 ` Thomas Monjalon
2018-04-17 10:31 ` Burakov, Anatoly
2018-04-17 11:16 ` zhouyangchao
2018-04-17 11:47 ` Thomas Monjalon
2018-04-17 14:02 ` Burakov, Anatoly
2018-04-18 3:09 ` [dpdk-dev] [PATCH v3] mem: fix memory leaks of hugedir and replace snprintf Yangchao Zhou
2018-04-18 9:00 ` Thomas Monjalon
2018-04-18 9:25 ` Burakov, Anatoly
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1523958196-6408-1-git-send-email-zhouyates@gmail.com \
--to=zhouyates@gmail.com \
--cc=dev@dpdk.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).