* [dpdk-dev] [PATCH] mem: memory leaks of hubedir caused by strdup @ 2018-04-17 9:43 Yangchao Zhou 2018-04-17 9:57 ` Burakov, Anatoly 0 siblings, 1 reply; 11+ messages in thread From: Yangchao Zhou @ 2018-04-17 9:43 UTC (permalink / raw) To: dev; +Cc: thomas 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 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH] mem: memory leaks of hubedir caused by strdup 2018-04-17 9:43 [dpdk-dev] [PATCH] mem: memory leaks of hubedir caused by strdup Yangchao Zhou @ 2018-04-17 9:57 ` Burakov, Anatoly 2018-04-17 10:06 ` [dpdk-dev] [PATCH v2] " Yangchao Zhou 0 siblings, 1 reply; 11+ messages in thread From: Burakov, Anatoly @ 2018-04-17 9:57 UTC (permalink / raw) To: Yangchao Zhou, dev; +Cc: thomas On 17-Apr-18 10:43 AM, Yangchao Zhou wrote: > Fixes: cb97d93e9d3bb5607681085d20acaca1aa16deb1("mem: share hugepage info primary and secondary") > > Signed-off-by: Yangchao Zhou <zhouyates@gmail.com> > --- Please use proper formatting for "fixes" line (refer to DPDK docs for correct way to generate it). Also, this fixes a coverity defect, please also add the following line: Coverity issue: 272585 That said, for actual patch contents, Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> Thanks for fixing this! -- Thanks, Anatoly ^ permalink raw reply [flat|nested] 11+ messages in thread
* [dpdk-dev] [PATCH v2] mem: memory leaks of hubedir caused by strdup 2018-04-17 9:57 ` Burakov, Anatoly @ 2018-04-17 10:06 ` Yangchao Zhou 2018-04-17 10:24 ` Thomas Monjalon 0 siblings, 1 reply; 11+ messages in thread From: Yangchao Zhou @ 2018-04-17 10:06 UTC (permalink / raw) To: dev; +Cc: thomas, anatoly.burakov Coverity issue: 272585 Fixes: cb97d93e9d3b ("mem: share hugepage info primary and secondary") Signed-off-by: Yangchao Zhou <zhouyates@gmail.com> Acked-by: Anatoly Burakov <anatoly.burakov@intel.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 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH v2] mem: memory leaks of hubedir caused by strdup 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 0 siblings, 1 reply; 11+ messages in thread From: Thomas Monjalon @ 2018-04-17 10:24 UTC (permalink / raw) To: Yangchao Zhou; +Cc: dev, anatoly.burakov, bruce.richardson 17/04/2018 12:06, Yangchao Zhou: > Coverity issue: 272585 > Fixes: cb97d93e9d3b ("mem: share hugepage info primary and secondary") > > Signed-off-by: Yangchao Zhou <zhouyates@gmail.com> > Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> Better to provide a small explanation. > - retval = strdup(splitstr[MOUNTPT]); > + snprintf(hugedir, len, "%s", splitstr[MOUNTPT]); I think it is candidate to be replaced by strlcpy. Please check ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH v2] mem: memory leaks of hubedir caused by strdup 2018-04-17 10:24 ` Thomas Monjalon @ 2018-04-17 10:31 ` Burakov, Anatoly 2018-04-17 11:16 ` zhouyangchao 0 siblings, 1 reply; 11+ messages in thread From: Burakov, Anatoly @ 2018-04-17 10:31 UTC (permalink / raw) To: Thomas Monjalon, Yangchao Zhou; +Cc: dev, bruce.richardson On 17-Apr-18 11:24 AM, Thomas Monjalon wrote: > 17/04/2018 12:06, Yangchao Zhou: >> Coverity issue: 272585 >> Fixes: cb97d93e9d3b ("mem: share hugepage info primary and secondary") >> >> Signed-off-by: Yangchao Zhou <zhouyates@gmail.com> >> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> > > Better to provide a small explanation. > >> - retval = strdup(splitstr[MOUNTPT]); >> + snprintf(hugedir, len, "%s", splitstr[MOUNTPT]); > > I think it is candidate to be replaced by strlcpy. > Please check > Yes, it seems that strlcpy thingie was merged without much fanfare. I'll be submitting a patch fixing various usages of snprintf in my recent commits. I'm inclined to leave this as is for this commit, as it's not the purpose of this fix. -- Thanks, Anatoly ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH v2] mem: memory leaks of hubedir caused by strdup 2018-04-17 10:31 ` Burakov, Anatoly @ 2018-04-17 11:16 ` zhouyangchao 2018-04-17 11:47 ` Thomas Monjalon 0 siblings, 1 reply; 11+ messages in thread From: zhouyangchao @ 2018-04-17 11:16 UTC (permalink / raw) To: Thomas Monjalon; +Cc: Burakov, Anatoly, dev, bruce.richardson As Burakov said, for no other reason, I just followed the old version. On Tue, Apr 17, 2018 at 6:31 PM Burakov, Anatoly <anatoly.burakov@intel.com> wrote: > On 17-Apr-18 11:24 AM, Thomas Monjalon wrote: > > 17/04/2018 12:06, Yangchao Zhou: > >> Coverity issue: 272585 > >> Fixes: cb97d93e9d3b ("mem: share hugepage info primary and secondary") > >> > >> Signed-off-by: Yangchao Zhou <zhouyates@gmail.com> > >> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> > > > > Better to provide a small explanation. > > > >> - retval = strdup(splitstr[MOUNTPT]); > >> + snprintf(hugedir, len, "%s", > splitstr[MOUNTPT]); > > > > I think it is candidate to be replaced by strlcpy. > > Please check > > > > Yes, it seems that strlcpy thingie was merged without much fanfare. I'll > be submitting a patch fixing various usages of snprintf in my recent > commits. I'm inclined to leave this as is for this commit, as it's not > the purpose of this fix. > > -- > Thanks, > Anatoly > ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH v2] mem: memory leaks of hubedir caused by strdup 2018-04-17 11:16 ` zhouyangchao @ 2018-04-17 11:47 ` Thomas Monjalon 2018-04-17 14:02 ` Burakov, Anatoly 0 siblings, 1 reply; 11+ messages in thread From: Thomas Monjalon @ 2018-04-17 11:47 UTC (permalink / raw) To: zhouyangchao; +Cc: dev, Burakov, Anatoly, bruce.richardson I see no reason to accept this patch, replacing strdup by snprintf, given that we have strlcpy. Please do a v3 with strlcpy. 17/04/2018 13:16, zhouyangchao: > As Burakov said, for no other reason, I just followed the old version. > > On Tue, Apr 17, 2018 at 6:31 PM Burakov, Anatoly <anatoly.burakov@intel.com> > wrote: > > > On 17-Apr-18 11:24 AM, Thomas Monjalon wrote: > > > 17/04/2018 12:06, Yangchao Zhou: > > >> Coverity issue: 272585 > > >> Fixes: cb97d93e9d3b ("mem: share hugepage info primary and secondary") > > >> > > >> Signed-off-by: Yangchao Zhou <zhouyates@gmail.com> > > >> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> > > > > > > Better to provide a small explanation. > > > > > >> - retval = strdup(splitstr[MOUNTPT]); > > >> + snprintf(hugedir, len, "%s", > > splitstr[MOUNTPT]); > > > > > > I think it is candidate to be replaced by strlcpy. > > > Please check > > > > > > > Yes, it seems that strlcpy thingie was merged without much fanfare. I'll > > be submitting a patch fixing various usages of snprintf in my recent > > commits. I'm inclined to leave this as is for this commit, as it's not > > the purpose of this fix. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH v2] mem: memory leaks of hubedir caused by strdup 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 0 siblings, 1 reply; 11+ messages in thread From: Burakov, Anatoly @ 2018-04-17 14:02 UTC (permalink / raw) To: Thomas Monjalon, zhouyangchao; +Cc: dev, bruce.richardson On 17-Apr-18 12:47 PM, Thomas Monjalon wrote: > I see no reason to accept this patch, replacing strdup by snprintf, > given that we have strlcpy. > Please do a v3 with strlcpy. OK. Please also fix the typo in patch headline :) -- Thanks, Anatoly ^ permalink raw reply [flat|nested] 11+ messages in thread
* [dpdk-dev] [PATCH v3] mem: fix memory leaks of hugedir and replace snprintf 2018-04-17 14:02 ` Burakov, Anatoly @ 2018-04-18 3:09 ` Yangchao Zhou 2018-04-18 9:00 ` Thomas Monjalon 0 siblings, 1 reply; 11+ messages in thread From: Yangchao Zhou @ 2018-04-18 3:09 UTC (permalink / raw) To: dev; +Cc: thomas, anatoly.burakov The hugedir returned by get_hugepage_dir is allocated by strdup but not released. Replace snprintf with a more suitable strlcpy. Coverity issue: 272585 Fixes: cb97d93e9d3b ("mem: share hugepage info primary and secondary") Signed-off-by: Yangchao Zhou <zhouyates@gmail.com> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> --- lib/librte_eal/bsdapp/eal/eal_hugepage_info.c | 2 +- lib/librte_eal/linuxapp/eal/eal_hugepage_info.c | 18 +++++++++--------- lib/librte_eal/linuxapp/eal/eal_memory.c | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal_hugepage_info.c b/lib/librte_eal/bsdapp/eal/eal_hugepage_info.c index 38d143c..836feb6 100644 --- a/lib/librte_eal/bsdapp/eal/eal_hugepage_info.c +++ b/lib/librte_eal/bsdapp/eal/eal_hugepage_info.c @@ -96,7 +96,7 @@ RTE_LOG(INFO, EAL, "Contigmem driver has %d buffers, each of size %dKB\n", num_buffers, (int)(buffer_size>>10)); - snprintf(hpi->hugedir, sizeof(hpi->hugedir), "%s", CONTIGMEM_DEV); + strlcpy(hpi->hugedir, CONTIGMEM_DEV, sizeof(hpi->hugedir)); hpi->hugepage_sz = buffer_size; hpi->num_pages[0] = num_buffers; hpi->lock_descriptor = fd; diff --git a/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c b/lib/librte_eal/linuxapp/eal/eal_hugepage_info.c index fb4b667..db5aabd 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]); + strlcpy(hugedir, splitstr[MOUNTPT], len); + 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]); + strlcpy(hugedir, splitstr[MOUNTPT], len); + 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); diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index b7a2e95..fadc1de 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -1160,8 +1160,8 @@ void numa_error(char *where) for (socket = 0; socket < RTE_MAX_NUMA_NODES && total_mem != 0; socket++) { /* skips if the memory on specific socket wasn't requested */ for (i = 0; i < num_hp_info && memory[socket] != 0; i++){ - snprintf(hp_used[i].hugedir, sizeof(hp_used[i].hugedir), - "%s", hp_info[i].hugedir); + strlcpy(hp_used[i].hugedir, hp_info[i].hugedir, + sizeof(hp_used[i].hugedir)); hp_used[i].num_pages[socket] = RTE_MIN( memory[socket] / hp_info[i].hugepage_sz, hp_info[i].num_pages[socket]); -- 1.7.1 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH v3] mem: fix memory leaks of hugedir and replace snprintf 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 0 siblings, 1 reply; 11+ messages in thread From: Thomas Monjalon @ 2018-04-18 9:00 UTC (permalink / raw) To: Yangchao Zhou; +Cc: dev, anatoly.burakov 18/04/2018 05:09, Yangchao Zhou: > The hugedir returned by get_hugepage_dir is allocated by strdup > but not released. Replace snprintf with a more suitable strlcpy. > > Coverity issue: 272585 > Fixes: cb97d93e9d3b ("mem: share hugepage info primary and secondary") > > Signed-off-by: Yangchao Zhou <zhouyates@gmail.com> > Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> There was a misunderstanding. You replaced some snprintf which were not involved in the leaks. But I think it's fine. Applied, thanks ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [dpdk-dev] [PATCH v3] mem: fix memory leaks of hugedir and replace snprintf 2018-04-18 9:00 ` Thomas Monjalon @ 2018-04-18 9:25 ` Burakov, Anatoly 0 siblings, 0 replies; 11+ messages in thread From: Burakov, Anatoly @ 2018-04-18 9:25 UTC (permalink / raw) To: Thomas Monjalon, Yangchao Zhou; +Cc: dev On 18-Apr-18 10:00 AM, Thomas Monjalon wrote: > 18/04/2018 05:09, Yangchao Zhou: >> The hugedir returned by get_hugepage_dir is allocated by strdup >> but not released. Replace snprintf with a more suitable strlcpy. >> >> Coverity issue: 272585 >> Fixes: cb97d93e9d3b ("mem: share hugepage info primary and secondary") >> >> Signed-off-by: Yangchao Zhou <zhouyates@gmail.com> >> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com> > > There was a misunderstanding. > You replaced some snprintf which were not involved in the leaks. > But I think it's fine. > > Applied, thanks > I'll check to see if i have to rebase my strlcpy patchset. -- Thanks, Anatoly ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2018-04-18 9:25 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-04-17 9:43 [dpdk-dev] [PATCH] mem: memory leaks of hubedir caused by strdup Yangchao Zhou 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
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).