DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] cfgfile: fix resource leak
@ 2017-10-26  6:21 Jacek Piasecki
  2017-10-27 15:08 ` Jastrzebski, MichalX K
  0 siblings, 1 reply; 3+ messages in thread
From: Jacek Piasecki @ 2017-10-26  6:21 UTC (permalink / raw)
  To: cristian.dumitrescu; +Cc: dev, Jacek Piasecki, stable

Unsuccesfull memory allocation for elements inside cfgfile
structure could result in resource leak.
Fixed by pointer verification after each malloc,
if malloc fail - error branch is proceeded with freeing memory.

Coverity issue: 195032
Fixes: d4cb8197589d ("cfgfile: support runtime modification")
Cc: jacekx.piasecki@intel.com
Cc: stable@dpdk.org

Signed-off-by: Jacek Piasecki <jacekx.piasecki@intel.com>
---
 lib/librte_cfgfile/rte_cfgfile.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index 124aef5..2880b9a 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -298,7 +298,7 @@ rte_cfgfile_create(int flags)
 			CFG_ALLOC_SECTION_BATCH);
 
 	if (cfg->sections == NULL)
-		return NULL;
+		goto error1;
 
 	cfg->allocated_sections = CFG_ALLOC_SECTION_BATCH;
 
@@ -307,7 +307,7 @@ rte_cfgfile_create(int flags)
 			struct rte_cfgfile_entry) * CFG_ALLOC_ENTRY_BATCH);
 
 		if (cfg->sections[i].entries == NULL)
-			return NULL;
+			goto error1;
 
 		cfg->sections[i].num_entries = 0;
 		cfg->sections[i].allocated_entries = CFG_ALLOC_ENTRY_BATCH;
@@ -315,7 +315,21 @@ rte_cfgfile_create(int flags)
 
 	if (flags & CFG_FLAG_GLOBAL_SECTION)
 		rte_cfgfile_add_section(cfg, "GLOBAL");
+
 	return cfg;
+error1:
+	if (cfg->sections != NULL) {
+		for (i = 0; i < cfg->allocated_sections; i++) {
+			if (cfg->sections[i].entries != NULL) {
+				free(cfg->sections[i].entries);
+				cfg->sections[i].entries = NULL;
+			}
+		}
+		free(cfg->sections);
+		cfg->sections = NULL;
+	}
+	free(cfg);
+	return NULL;
 }
 
 int
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] cfgfile: fix resource leak
  2017-10-26  6:21 [dpdk-dev] [PATCH] cfgfile: fix resource leak Jacek Piasecki
@ 2017-10-27 15:08 ` Jastrzebski, MichalX K
  2017-11-07  1:20   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Jastrzebski, MichalX K @ 2017-10-27 15:08 UTC (permalink / raw)
  To: Piasecki, JacekX, Dumitrescu, Cristian; +Cc: dev, Piasecki, JacekX, stable

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Jacek Piasecki
> Sent: Thursday, October 26, 2017 8:21 AM
> To: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>
> Cc: dev@dpdk.org; Piasecki, JacekX <jacekx.piasecki@intel.com>;
> stable@dpdk.org
> Subject: [dpdk-dev] [PATCH] cfgfile: fix resource leak
> 
> Unsuccesfull memory allocation for elements inside cfgfile
> structure could result in resource leak.
> Fixed by pointer verification after each malloc,
> if malloc fail - error branch is proceeded with freeing memory.
> 
> Coverity issue: 195032
> Fixes: d4cb8197589d ("cfgfile: support runtime modification")
> Cc: jacekx.piasecki@intel.com
> Cc: stable@dpdk.org
> 
> Signed-off-by: Jacek Piasecki <jacekx.piasecki@intel.com>
> ---
>  lib/librte_cfgfile/rte_cfgfile.c | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
> index 124aef5..2880b9a 100644
> --- a/lib/librte_cfgfile/rte_cfgfile.c
> +++ b/lib/librte_cfgfile/rte_cfgfile.c
> @@ -298,7 +298,7 @@ rte_cfgfile_create(int flags)
>  			CFG_ALLOC_SECTION_BATCH);
> 
>  	if (cfg->sections == NULL)
> -		return NULL;
> +		goto error1;
> 
>  	cfg->allocated_sections = CFG_ALLOC_SECTION_BATCH;
> 
> @@ -307,7 +307,7 @@ rte_cfgfile_create(int flags)
>  			struct rte_cfgfile_entry) *
> CFG_ALLOC_ENTRY_BATCH);
> 
>  		if (cfg->sections[i].entries == NULL)
> -			return NULL;
> +			goto error1;
> 
>  		cfg->sections[i].num_entries = 0;
>  		cfg->sections[i].allocated_entries =
> CFG_ALLOC_ENTRY_BATCH;
> @@ -315,7 +315,21 @@ rte_cfgfile_create(int flags)
> 
>  	if (flags & CFG_FLAG_GLOBAL_SECTION)
>  		rte_cfgfile_add_section(cfg, "GLOBAL");
> +
>  	return cfg;
> +error1:
> +	if (cfg->sections != NULL) {
> +		for (i = 0; i < cfg->allocated_sections; i++) {
> +			if (cfg->sections[i].entries != NULL) {
> +				free(cfg->sections[i].entries);
> +				cfg->sections[i].entries = NULL;
> +			}
> +		}
> +		free(cfg->sections);
> +		cfg->sections = NULL;
> +	}
> +	free(cfg);
> +	return NULL;
>  }
> 
>  int
> --
> 2.7.4

Acked-by: Michal Jastrzebski <michalx.k.jastrzebski@intel.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] cfgfile: fix resource leak
  2017-10-27 15:08 ` Jastrzebski, MichalX K
@ 2017-11-07  1:20   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2017-11-07  1:20 UTC (permalink / raw)
  To: Piasecki, JacekX; +Cc: dev, Jastrzebski, MichalX K, Dumitrescu, Cristian

27/10/2017 17:08, Jastrzebski, MichalX K:
> > 
> > Unsuccesfull memory allocation for elements inside cfgfile
> > structure could result in resource leak.
> > Fixed by pointer verification after each malloc,
> > if malloc fail - error branch is proceeded with freeing memory.
> > 
> > Coverity issue: 195032
> > Fixes: d4cb8197589d ("cfgfile: support runtime modification")
> > Cc: jacekx.piasecki@intel.com
> > Cc: stable@dpdk.org

No need to Cc stable for bugs introduced in current release.

> > Signed-off-by: Jacek Piasecki <jacekx.piasecki@intel.com>
> 
> Acked-by: Michal Jastrzebski <michalx.k.jastrzebski@intel.com>

Applied, thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-07  1:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-26  6:21 [dpdk-dev] [PATCH] cfgfile: fix resource leak Jacek Piasecki
2017-10-27 15:08 ` Jastrzebski, MichalX K
2017-11-07  1:20   ` 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).