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

Re: PATCH: zsh-3.1.5-pws-4 + typeset fix: memory leak



On Jan 15,  4:44pm, Peter Stephenson wrote:
} Subject: PATCH: zsh-3.1.5-pws-4 + typeset fix: memory leak
}
} the problem with your approach is that `print -P' can take more than
} one argument, and all need freeing: the easiest thing to do is use
} heap memory (which gets freed automatically when the builtin exits),
} and free the permanent memory straight away.

Another place where 3.0.5 appears to have been patched but 3.1.5 has not.
The 3.0.5 code reads:

	/* -P option -- interpret as a prompt sequence */
	if(ops['P']) {
	    char *arg = putprompt(metafy(args[n], len[n], META_NOALLOC),
				  &len[n], NULL, 0);
	    args[n] = (char *)alloc(len[n] + 1);
	    memcpy(args[n], arg, len[n]);
	    args[n][len[n]] = 0;
	    free(arg);
	}

I'm sure the memcpy() is done to avoid recomputing len[n]+1 in dupstring().

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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