Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] fix several memory leaks



> 2018/07/29 01:34, I wrote:
> 
> V01zmodload.ztst has another type of leaks, but I will discuss
> it in a separate post because how to fix it (or whether it must
> be fixed or not) is not clear.

Here is the other leaks in V01zmodload.zsh:

[7] V01zmodload.ztst (part2: example.c)

The second type of leaks can be reproduced by:

    zsh% zmodload -ab zsh/example example
    zsh% zmodload -u zsh/example
    zsh% builtin example
    zsh% zmodload -u zsh/example

The 'builtin example' autoloads the builtin, and then calls
bin_example(), which allocates memory for 'strparam' and
'arrparam' at lines 71 and 74 in example.c. But these are not
freed by cleanup_(). At this point 'p:exstr' and 'p:exarr' are
not enabled, and setfeatureenables() takes care of only
enabled features.

If the first 'zomdload -u' is ommited then the leak does
not occur. In this case, all the features are enabled by
'builtin example', and the last 'zmodload -u' correctly
frees the memory for 'p:exstr' and 'p:exarr'.

Do we need to fix this leak?

If builtin and parameter are independent features, then
"a builtin depending on parameters" may not be a good
"example".


The patch below is NOT a fix; it is just to confirm that
what are leaking is 'strparam' and 'arrparam'. Parameters
are supposed to be freed by setfeatureenables(,,NULL),
and explicitly freeing them in cleanup_() is not a good
example.

diff --git a/Src/Modules/example.c b/Src/Modules/example.c
index c80c9e7b2..0cae3477d 100644
--- a/Src/Modules/example.c
+++ b/Src/Modules/example.c
@@ -234,6 +234,10 @@ boot_(Module m)
 int
 cleanup_(Module m)
 {
+    zsfree(strparam);
+    strparam = NULL;
+    freearray(arrparam);
+    arrparam = NULL;
     deletewrapper(m, wrapper);
     return setfeatureenables(m, &module_features, NULL);
 }




Messages sorted by: Reverse Date, Date, Thread, Author