zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: memory leak in anonoymous functions
@ 2010-12-03 23:20 Peter Stephenson
  2010-12-03 23:49 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2010-12-03 23:20 UTC (permalink / raw)
  To: Zsh hackers list

Found by valgrind.  It's reporting lots of possible leaks, but they're
very hard to track down.  For example,

		save = (!(state->prog->flags & EF_HEAP) &&
			!strcmp(opat, right) && pprog != dummy_patprog2);

		if (!(pprog = patcompile(right, (save ? PAT_ZDUP : PAT_STATIC),
					 NULL))) {
		    zwarnnam(fromtest, "bad pattern: %s", right);
		    return 2;
		}
		else if (save)
		    state->prog->pats[npat] = pprog;

That pprog might be leaked, it says.  Er, yeah, right.

It's also very suspicious of parameters, particularly complicated uses
like tied parameters and autoloaded parameters.

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.185
diff -p -u -r1.185 exec.c
--- Src/exec.c	27 Nov 2010 19:46:32 -0000	1.185
+++ Src/exec.c	3 Dec 2010 23:14:32 -0000
@@ -4159,6 +4159,10 @@ execfuncdef(Estate state, UNUSED(int do_
 
 	    execshfunc(shf, args);
 	    ret = lastval;
+
+	    freeeprog(shf->funcdef);
+	    zsfree(shf->filename);
+	    zfree(shf, sizeof(*shf));
 	    break;
 	} else {
 	    /* is this shell function a signal trap? */

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* Re: PATCH: memory leak in anonoymous functions
  2010-12-03 23:20 PATCH: memory leak in anonoymous functions Peter Stephenson
@ 2010-12-03 23:49 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2010-12-03 23:49 UTC (permalink / raw)
  To: Zsh hackers list

On Dec 3, 11:20pm, Peter Stephenson wrote:
}
} 		save = (!(state->prog->flags & EF_HEAP) &&
} 			!strcmp(opat, right) && pprog != dummy_patprog2);
} 
} 		if (!(pprog = patcompile(right, (save ? PAT_ZDUP : PAT_STATIC),
} 					 NULL))) {
} 		    zwarnnam(fromtest, "bad pattern: %s", right);
} 		    return 2;
} 		}
} 		else if (save)
} 		    state->prog->pats[npat] = pprog;
} 
} That pprog might be leaked, it says.  Er, yeah, right.

Well, if save is false but patcompile() returns non-null, then pprog
is never assigned anywhere.  But if save is false then patcompile() was
called with PAT_STATIC and there's nothing to free.  It's not very
surprising that a compile-time analysis wouldn't figure that out, but
valgrind does runtime analysis ...

Which would mean that state->prog->pats[] is what's being leaked ...,
sometime after evalcond() returns?


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

end of thread, other threads:[~2010-12-03 23:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-03 23:20 PATCH: memory leak in anonoymous functions Peter Stephenson
2010-12-03 23:49 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).