mountd: Fix memory leak in getexportent
Subsystems (2)
PATCH 1/1 mountd: Fix memory leak in getexportent
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 <[email protected]>
--- support/nfs/exports.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
support/nfs/exports.c +1 -1
@@ -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 )
Signature · 1 line
1.9.3
Quoted 7 lines · Scott Mayhew
Valgrind shows that the memory allocated for ee.e_hostname in
getexportent()is being leaked. While there _is_ a call toxfree(), by the time it gets called the leak's already happened. Moving thexfree()call so that it occurs before the assignment that overwrites ee fixes this.Signed-off-by Scott Mayhew <[email protected]>
Committed!
steved.
Quoted 25 lines
--- support/nfs/exports.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)support/nfs/exports.c +1
-1@@ -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 )