diff mbox

[nfs-utils] mountd: Fix memory leak in getexportent

Message ID 1424458167-58324-1-git-send-email-smayhew@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Scott Mayhew Feb. 20, 2015, 6:49 p.m. UTC
Valgrind shows that the memory allocated for ee.e_hostname in
getexportent() is being leaked.  While there _is_ a call to xfree(), by
the time it gets called the leak's already happened.  Moving the xfree()
call so that it occurs before the assignment that overwrites ee fixes
this.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
---
 support/nfs/exports.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Steve Dickson Feb. 26, 2015, 7:36 p.m. UTC | #1
On 02/20/2015 01:49 PM, Scott Mayhew wrote:
> Valgrind shows that the memory allocated for ee.e_hostname in
> getexportent() is being leaked.  While there _is_ a call to xfree(), by
> the time it gets called the leak's already happened.  Moving the xfree()
> call so that it occurs before the assignment that overwrites ee fixes
> this.
> 
> Signed-off-by: Scott Mayhew <smayhew@redhat.com>
Committed! 

steved.

> ---
>  support/nfs/exports.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/support/nfs/exports.c b/support/nfs/exports.c
> index eb782b9..4b17d3c 100644
> --- a/support/nfs/exports.c
> +++ b/support/nfs/exports.c
> @@ -154,6 +154,7 @@ getexportent(int fromkernel, int fromexports)
>  		}
>  	}
>  
> +	xfree(ee.e_hostname);
>  	ee = def_ee;
>  
>  	/* Check for default client */
> @@ -176,7 +177,6 @@ getexportent(int fromkernel, int fromexports)
>  		if (!has_default_opts)
>  			xlog(L_WARNING, "No options for %s %s: suggest %s(sync) to avoid warning", ee.e_path, exp, exp);
>  	}
> -	xfree(ee.e_hostname);
>  	ee.e_hostname = xstrdup(hostname);
>  
>  	if (parseopts(opt, &ee, fromexports && !has_default_subtree_opts, NULL) < 0)
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/support/nfs/exports.c b/support/nfs/exports.c
index eb782b9..4b17d3c 100644
--- a/support/nfs/exports.c
+++ b/support/nfs/exports.c
@@ -154,6 +154,7 @@  getexportent(int fromkernel, int fromexports)
 		}
 	}
 
+	xfree(ee.e_hostname);
 	ee = def_ee;
 
 	/* Check for default client */
@@ -176,7 +177,6 @@  getexportent(int fromkernel, int fromexports)
 		if (!has_default_opts)
 			xlog(L_WARNING, "No options for %s %s: suggest %s(sync) to avoid warning", ee.e_path, exp, exp);
 	}
-	xfree(ee.e_hostname);
 	ee.e_hostname = xstrdup(hostname);
 
 	if (parseopts(opt, &ee, fromexports && !has_default_subtree_opts, NULL) < 0)