summaryrefslogtreecommitdiff
path: root/Src/module.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-03-18 12:23:31 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-03-18 12:23:31 +0000
commit2f8a646d4e68d3f515d0b5275d179562a219a9ed (patch)
tree0f7dd607386e8a2eb094f30fd3f764e2288cbf05 /Src/module.c
parent91f0b666d00e58c50537d1ca48d90b1af8a25ae7 (diff)
downloadzsh-2f8a646d4e68d3f515d0b5275d179562a219a9ed.tar.gz
zsh-2f8a646d4e68d3f515d0b5275d179562a219a9ed.zip
19655, 19656, 19657: Memory leaks spotted by valgrind.
Also bug with multiple math function autoloads.
Diffstat (limited to 'Src/module.c')
-rw-r--r--Src/module.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/Src/module.c b/Src/module.c
index 3a89294e5..4a4807a31 100644
--- a/Src/module.c
+++ b/Src/module.c
@@ -2039,6 +2039,19 @@ add_autoparam(char *nam, char *module)
MathFunc mathfuncs;
/**/
+static void removemathfunc(MathFunc previous, MathFunc current)
+{
+ if (previous)
+ previous->next = current->next;
+ else
+ mathfuncs = current->next;
+
+ zsfree(current->name);
+ zsfree(current->module);
+ zfree(current, sizeof(*current));
+}
+
+/**/
MathFunc
getmathfunc(char *name, int autol)
{
@@ -2049,13 +2062,7 @@ getmathfunc(char *name, int autol)
if (autol && p->module) {
char *n = dupstring(p->module);
- if (q)
- q->next = p->next;
- else
- mathfuncs = p->next;
-
- zsfree(p->module);
- zfree(p, sizeof(*p));
+ removemathfunc(q, p);
load_module(n);
@@ -2071,14 +2078,22 @@ getmathfunc(char *name, int autol)
mod_export int
addmathfunc(MathFunc f)
{
- MathFunc p;
+ MathFunc p, q = NULL;
if (f->flags & MFF_ADDED)
return 1;
- for (p = mathfuncs; p; p = p->next)
- if (!strcmp(f->name, p->name))
+ for (p = mathfuncs; p; q = p, p = p->next)
+ if (!strcmp(f->name, p->name)) {
+ if (p->module) {
+ /*
+ * Autoloadable, replace.
+ */
+ removemathfunc(q, p);
+ break;
+ }
return 1;
+ }
f->flags |= MFF_ADDED;
f->next = mathfuncs;