Attached patch fixes the memory leaks related to Perl_newCONSTSUB(). 0:malloc 1:Perl_safesysmalloc (util.c:70) 2:Perl_savepv (util.c:753) 3:Perl_newCONSTSUB (op.c:4445) This leaks memory because in the call cv = newXS(name, const_sv_xsub, savepv(CopFILE(PL_curcop))); the filename CopFILE(PL_curcop) is copied, but Perl_newXS assumes that filename is static (and thus doesn't copy it). Perl_cv_undef() knows about that and doesn't free CvFILE(cv) for XSUBs. So the copied filename isn't freed. The patched code checks if it's a CONSTSUB and frees the memory. 0:malloc 1:Perl_savesharedpv (util.c:802) 2:Perl_newCONSTSUB (op.c:4442) This leaks because in Perl_newCONSTSUB() (only interesting bits) if (stash) { SAVECOPSTASH(PL_curcop); CopSTASH_set(PL_curcop,stash); } cv = newXS(name, const_sv_xsub, savepv(CopFILE(PL_curcop))); LEAVE; CopSTASHPV(PL_curcop) is first saved, then it is set to a freshly allocated block, and at the end of the routine LEAVE restores the old cop_stashpv, and there's our leak. Perl_newXS() needs CopSTASH(PL_curcop) only once (within Perl_gv_fetchpv(), to look up the stash), but it won't keep a reference on it. The patched code will CopSTASH_free(PL_curcop) before LEAVEing. -- MarcusThread Next