* [dpdk-dev] [PATCH] eal/linuxapp: fix resource leak
@ 2016-05-11 16:01 Daniel Mrzyglod
2016-05-12 7:55 ` Sergio Gonzalez Monroy
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Daniel Mrzyglod @ 2016-05-11 16:01 UTC (permalink / raw)
To: sergio.gonzalez.monroy, david.marchand; +Cc: dev, Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 97920
munmap structure of hugepage
leaked_storage: Variable hugepage going out of scope leaks the storage
it points to.
The system resource will not be reclaimed and reused, reducing the future
availability of the resource.
In rte_eal_hugepage_init: Leak of memory or pointers to system resources
Fixes: b6a468ad41d5 ("memory: add --socket-mem option")
Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
---
lib/librte_eal/linuxapp/eal/eal_memory.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 5b9132c..cd40cc9 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1051,7 +1051,7 @@ int
rte_eal_hugepage_init(void)
{
struct rte_mem_config *mcfg;
- struct hugepage_file *hugepage, *tmp_hp = NULL;
+ struct hugepage_file *hugepage = NULL, *tmp_hp = NULL;
struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
uint64_t memory[RTE_MAX_NUMA_NODES];
@@ -1374,6 +1374,8 @@ rte_eal_hugepage_init(void)
fail:
free(tmp_hp);
+ if (hugepage != NULL)
+ munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
return -1;
}
--
2.5.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH] eal/linuxapp: fix resource leak
2016-05-11 16:01 [dpdk-dev] [PATCH] eal/linuxapp: fix resource leak Daniel Mrzyglod
@ 2016-05-12 7:55 ` Sergio Gonzalez Monroy
2016-05-13 10:28 ` Thomas Monjalon
2016-05-12 9:12 ` [dpdk-dev] [PATCH v2] " Daniel Mrzyglod
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Sergio Gonzalez Monroy @ 2016-05-12 7:55 UTC (permalink / raw)
To: Daniel Mrzyglod; +Cc: dev, david.marchand
Hi,
On 11/05/2016 17:01, Daniel Mrzyglod wrote:
> Fix issue reported by Coverity.
> Coverity ID 97920
>
> munmap structure of hugepage
>
> leaked_storage: Variable hugepage going out of scope leaks the storage
> it points to.
>
> The system resource will not be reclaimed and reused, reducing the future
> availability of the resource.
I'm not really fond of this commit messages, but if no one minds them,
so be it.
> In rte_eal_hugepage_init: Leak of memory or pointers to system resources
>
> Fixes: b6a468ad41d5 ("memory: add --socket-mem option")
>
> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
> ---
> lib/librte_eal/linuxapp/eal/eal_memory.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
> index 5b9132c..cd40cc9 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_memory.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
> @@ -1051,7 +1051,7 @@ int
> rte_eal_hugepage_init(void)
> {
> struct rte_mem_config *mcfg;
> - struct hugepage_file *hugepage, *tmp_hp = NULL;
> + struct hugepage_file *hugepage = NULL, *tmp_hp = NULL;
> struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
>
> uint64_t memory[RTE_MAX_NUMA_NODES];
> @@ -1374,6 +1374,8 @@ rte_eal_hugepage_init(void)
>
> fail:
> free(tmp_hp);
> + if (hugepage != NULL)
> + munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
> return -1;
> }
>
You missed the last conditional if(...0 of the function where it returns
directly with error value.
Looking at the code a bit, we never check for anything other than < 0
return value, so I'd just do a 'goto fail' instead.
Sergio
^ permalink raw reply [flat|nested] 10+ messages in thread
* [dpdk-dev] [PATCH v2] eal/linuxapp: fix resource leak
2016-05-11 16:01 [dpdk-dev] [PATCH] eal/linuxapp: fix resource leak Daniel Mrzyglod
2016-05-12 7:55 ` Sergio Gonzalez Monroy
@ 2016-05-12 9:12 ` Daniel Mrzyglod
2016-06-20 9:33 ` Thomas Monjalon
2016-06-22 16:50 ` [dpdk-dev] [PATCH v3] " Daniel Mrzyglod
2016-07-06 10:44 ` [dpdk-dev] [PATCH v4] " Daniel Mrzyglod
3 siblings, 1 reply; 10+ messages in thread
From: Daniel Mrzyglod @ 2016-05-12 9:12 UTC (permalink / raw)
To: sergio.gonzalez.monroy, david.marchand; +Cc: dev, Daniel Mrzyglod
Fix issue reported by Coverity.
Coverity ID 97920
munmap structure of hugepage
leaked_storage: Variable hugepage going out of scope leaks the storage
it points to.
The system resource will not be reclaimed and reused, reducing the future
availability of the resource.
In rte_eal_hugepage_init: Leak of memory or pointers to system resources
Fixes: b6a468ad41d5 ("memory: add --socket-mem option")
Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
---
lib/librte_eal/linuxapp/eal/eal_memory.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 5b9132c..9fd0d8d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1051,7 +1051,7 @@ int
rte_eal_hugepage_init(void)
{
struct rte_mem_config *mcfg;
- struct hugepage_file *hugepage, *tmp_hp = NULL;
+ struct hugepage_file *hugepage = NULL, *tmp_hp = NULL;
struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
uint64_t memory[RTE_MAX_NUMA_NODES];
@@ -1367,13 +1367,15 @@ rte_eal_hugepage_init(void)
"of memory.\n",
i, nr_hugefiles, RTE_STR(CONFIG_RTE_MAX_MEMSEG),
RTE_MAX_MEMSEG);
- return -ENOMEM;
+ goto fail;
}
return 0;
fail:
free(tmp_hp);
+ if (hugepage != NULL)
+ munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
return -1;
}
--
2.5.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH] eal/linuxapp: fix resource leak
2016-05-12 7:55 ` Sergio Gonzalez Monroy
@ 2016-05-13 10:28 ` Thomas Monjalon
0 siblings, 0 replies; 10+ messages in thread
From: Thomas Monjalon @ 2016-05-13 10:28 UTC (permalink / raw)
To: Sergio Gonzalez Monroy, Daniel Mrzyglod; +Cc: dev, david.marchand
2016-05-12 08:55, Sergio Gonzalez Monroy:
> On 11/05/2016 17:01, Daniel Mrzyglod wrote:
> > Fix issue reported by Coverity.
> > Coverity ID 97920
> >
> > munmap structure of hugepage
> >
> > leaked_storage: Variable hugepage going out of scope leaks the storage
> > it points to.
> >
> > The system resource will not be reclaimed and reused, reducing the future
> > availability of the resource.
>
> I'm not really fond of this commit messages, but if no one minds them,
> so be it.
Me too. It looks like a Machine2Machine message.
I'd prefer an explanation of what is wrong first, then an explanation of
the fix, and at the end, the Coverity ID (can be a tag like
Fixes-Coverity-ID: 97920).
> > In rte_eal_hugepage_init: Leak of memory or pointers to system resources
> >
> > Fixes: b6a468ad41d5 ("memory: add --socket-mem option")
> >
> > Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH v2] eal/linuxapp: fix resource leak
2016-05-12 9:12 ` [dpdk-dev] [PATCH v2] " Daniel Mrzyglod
@ 2016-06-20 9:33 ` Thomas Monjalon
0 siblings, 0 replies; 10+ messages in thread
From: Thomas Monjalon @ 2016-06-20 9:33 UTC (permalink / raw)
To: Daniel Mrzyglod; +Cc: dev, sergio.gonzalez.monroy, david.marchand
2016-05-12 11:12, Daniel Mrzyglod:
> Fix issue reported by Coverity.
> Coverity ID 97920
>
> munmap structure of hugepage
>
> leaked_storage: Variable hugepage going out of scope leaks the storage
> it points to.
>
> The system resource will not be reclaimed and reused, reducing the future
> availability of the resource.
>
> In rte_eal_hugepage_init: Leak of memory or pointers to system resources
Please reword.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [dpdk-dev] [PATCH v3] eal/linuxapp: fix resource leak
2016-05-11 16:01 [dpdk-dev] [PATCH] eal/linuxapp: fix resource leak Daniel Mrzyglod
2016-05-12 7:55 ` Sergio Gonzalez Monroy
2016-05-12 9:12 ` [dpdk-dev] [PATCH v2] " Daniel Mrzyglod
@ 2016-06-22 16:50 ` Daniel Mrzyglod
2016-06-30 13:31 ` Sergio Gonzalez Monroy
2016-07-06 10:44 ` [dpdk-dev] [PATCH v4] " Daniel Mrzyglod
3 siblings, 1 reply; 10+ messages in thread
From: Daniel Mrzyglod @ 2016-06-22 16:50 UTC (permalink / raw)
To: sergio.gonzalez.monroy, david.marchand; +Cc: dev, Daniel Mrzyglod
This patch fix all cases to do proper handle all munmap if pointer
of hugepage is not NULL which prohibits resource leak.
Coverity issue: 97920
Fixes: b6a468ad41d5 ("memory: add --socket-mem option")
Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
---
lib/librte_eal/linuxapp/eal/eal_memory.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 9251a5b..9b0d39a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1051,7 +1051,7 @@ int
rte_eal_hugepage_init(void)
{
struct rte_mem_config *mcfg;
- struct hugepage_file *hugepage, *tmp_hp = NULL;
+ struct hugepage_file *hugepage = NULL, *tmp_hp = NULL;
struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
uint64_t memory[RTE_MAX_NUMA_NODES];
@@ -1367,13 +1367,15 @@ rte_eal_hugepage_init(void)
"of memory.\n",
i, nr_hugefiles, RTE_STR(CONFIG_RTE_MAX_MEMSEG),
RTE_MAX_MEMSEG);
- return -ENOMEM;
+ goto fail;
}
return 0;
fail:
free(tmp_hp);
+ if (hugepage != NULL)
+ munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
return -1;
}
--
2.7.4
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH v3] eal/linuxapp: fix resource leak
2016-06-22 16:50 ` [dpdk-dev] [PATCH v3] " Daniel Mrzyglod
@ 2016-06-30 13:31 ` Sergio Gonzalez Monroy
0 siblings, 0 replies; 10+ messages in thread
From: Sergio Gonzalez Monroy @ 2016-06-30 13:31 UTC (permalink / raw)
To: Daniel Mrzyglod, david.marchand; +Cc: dev
On 22/06/2016 17:50, Daniel Mrzyglod wrote:
> This patch fix all cases to do proper handle all munmap if pointer
> of hugepage is not NULL which prohibits resource leak.
I would reword the above commit to something like:
Current code does not munmap 'hugepage' mapping (hugepage info file) on
function
exit, leaking resources.
> Coverity issue: 97920
> Fixes: b6a468ad41d5 ("memory: add --socket-mem option")
>
> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
> ---
> lib/librte_eal/linuxapp/eal/eal_memory.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
> index 9251a5b..9b0d39a 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_memory.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
> @@ -1051,7 +1051,7 @@ int
> rte_eal_hugepage_init(void)
> {
> struct rte_mem_config *mcfg;
> - struct hugepage_file *hugepage, *tmp_hp = NULL;
> + struct hugepage_file *hugepage = NULL, *tmp_hp = NULL;
> struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
>
> uint64_t memory[RTE_MAX_NUMA_NODES];
> @@ -1367,13 +1367,15 @@ rte_eal_hugepage_init(void)
> "of memory.\n",
> i, nr_hugefiles, RTE_STR(CONFIG_RTE_MAX_MEMSEG),
> RTE_MAX_MEMSEG);
> - return -ENOMEM;
> + goto fail;
> }
>
I missed this but we should also munmap 'hugepage' on successful
function exit.
Sergio
> return 0;
>
> fail:
> free(tmp_hp);
> + if (hugepage != NULL)
> + munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
> return -1;
> }
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [dpdk-dev] [PATCH v4] eal/linuxapp: fix resource leak
2016-05-11 16:01 [dpdk-dev] [PATCH] eal/linuxapp: fix resource leak Daniel Mrzyglod
` (2 preceding siblings ...)
2016-06-22 16:50 ` [dpdk-dev] [PATCH v3] " Daniel Mrzyglod
@ 2016-07-06 10:44 ` Daniel Mrzyglod
2016-07-06 10:48 ` Sergio Gonzalez Monroy
3 siblings, 1 reply; 10+ messages in thread
From: Daniel Mrzyglod @ 2016-07-06 10:44 UTC (permalink / raw)
To: sergio.gonzalez.monroy, david.marchand; +Cc: dev, Daniel Mrzyglod
Current code does not munmap 'hugepage' mapping (hugepage info file) on
function exit, leaking resources.
Coverity issue: 97920
Fixes: b6a468ad41d5 ("memory: add --socket-mem option")
Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
---
lib/librte_eal/linuxapp/eal/eal_memory.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 5578c25..b663244 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1136,7 +1136,7 @@ int
rte_eal_hugepage_init(void)
{
struct rte_mem_config *mcfg;
- struct hugepage_file *hugepage, *tmp_hp = NULL;
+ struct hugepage_file *hugepage = NULL, *tmp_hp = NULL;
struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
uint64_t memory[RTE_MAX_NUMA_NODES];
@@ -1479,14 +1479,19 @@ rte_eal_hugepage_init(void)
"of memory.\n",
i, nr_hugefiles, RTE_STR(CONFIG_RTE_MAX_MEMSEG),
RTE_MAX_MEMSEG);
- return -ENOMEM;
+ goto fail;
}
+ munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
+
return 0;
fail:
huge_recover_sigbus();
free(tmp_hp);
+ if (hugepage != NULL)
+ munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
+
return -1;
}
--
2.7.4
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH v4] eal/linuxapp: fix resource leak
2016-07-06 10:44 ` [dpdk-dev] [PATCH v4] " Daniel Mrzyglod
@ 2016-07-06 10:48 ` Sergio Gonzalez Monroy
2016-07-10 13:29 ` Thomas Monjalon
0 siblings, 1 reply; 10+ messages in thread
From: Sergio Gonzalez Monroy @ 2016-07-06 10:48 UTC (permalink / raw)
To: Daniel Mrzyglod, david.marchand; +Cc: dev
On 06/07/2016 11:44, Daniel Mrzyglod wrote:
> Current code does not munmap 'hugepage' mapping (hugepage info file) on
> function exit, leaking resources.
>
> Coverity issue: 97920
> Fixes: b6a468ad41d5 ("memory: add --socket-mem option")
>
> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
> ---
Please next time remember to keep patch version history after the triple
dashes.
Acked-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [dpdk-dev] [PATCH v4] eal/linuxapp: fix resource leak
2016-07-06 10:48 ` Sergio Gonzalez Monroy
@ 2016-07-10 13:29 ` Thomas Monjalon
0 siblings, 0 replies; 10+ messages in thread
From: Thomas Monjalon @ 2016-07-10 13:29 UTC (permalink / raw)
To: Daniel Mrzyglod; +Cc: dev, Sergio Gonzalez Monroy, david.marchand
2016-07-06 11:48, Sergio Gonzalez Monroy:
> On 06/07/2016 11:44, Daniel Mrzyglod wrote:
> > Current code does not munmap 'hugepage' mapping (hugepage info file) on
> > function exit, leaking resources.
> >
> > Coverity issue: 97920
> > Fixes: b6a468ad41d5 ("memory: add --socket-mem option")
> >
> > Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
> > ---
>
> Please next time remember to keep patch version history after the triple
> dashes.
>
> Acked-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
Applied, thanks
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2016-07-10 13:29 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-11 16:01 [dpdk-dev] [PATCH] eal/linuxapp: fix resource leak Daniel Mrzyglod
2016-05-12 7:55 ` Sergio Gonzalez Monroy
2016-05-13 10:28 ` Thomas Monjalon
2016-05-12 9:12 ` [dpdk-dev] [PATCH v2] " Daniel Mrzyglod
2016-06-20 9:33 ` Thomas Monjalon
2016-06-22 16:50 ` [dpdk-dev] [PATCH v3] " Daniel Mrzyglod
2016-06-30 13:31 ` Sergio Gonzalez Monroy
2016-07-06 10:44 ` [dpdk-dev] [PATCH v4] " Daniel Mrzyglod
2016-07-06 10:48 ` Sergio Gonzalez Monroy
2016-07-10 13:29 ` Thomas Monjalon
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).