From: Jarkko Hietaniemi Date: Tue, 29 Jul 2003 10:14:26 +0000 (+0000) Subject: Most importantly, don't try HvNAME(gp->gp_hv) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=13207a7148ab5967a6d91a9acb60e5e292572de2;p=p5sagit%2Fp5-mst-13.2.git Most importantly, don't try HvNAME(gp->gp_hv) unless PL_stashcache exists, otherwise we get an invalid read (detected by valgrind, and crashes ext/threads/t/basic.t in Windows). Also add a few if:s for the refcnt decrements, no need to call Perl_sv_free() if there's nothing to free. p4raw-id: //depot/perl@20292 --- diff --git a/gv.c b/gv.c index a5dbb95..8a9b803 100644 --- a/gv.c +++ b/gv.c @@ -1252,14 +1252,18 @@ Perl_gp_free(pTHX_ GV *gv) return; } - SvREFCNT_dec(gp->gp_sv); - SvREFCNT_dec(gp->gp_av); - if(gp->gp_hv && HvNAME(gp->gp_hv) && PL_stashcache) - hv_delete(PL_stashcache, HvNAME(gp->gp_hv), strlen(HvNAME(gp->gp_hv)), G_DISCARD); - SvREFCNT_dec(gp->gp_hv); - SvREFCNT_dec(gp->gp_io); - SvREFCNT_dec(gp->gp_cv); - SvREFCNT_dec(gp->gp_form); + if (gp->gp_sv) SvREFCNT_dec(gp->gp_sv); + if (gp->gp_sv) SvREFCNT_dec(gp->gp_av); + if (gp->gp_hv) { + if (PL_stashcache && HvNAME(gp->gp_hv)) + hv_delete(PL_stashcache, + HvNAME(gp->gp_hv), strlen(HvNAME(gp->gp_hv)), + G_DISCARD); + SvREFCNT_dec(gp->gp_hv); + } + if (gp->gp_io) SvREFCNT_dec(gp->gp_io); + if (gp->gp_cv) SvREFCNT_dec(gp->gp_cv); + if (gp->gp_form) SvREFCNT_dec(gp->gp_form); Safefree(gp); GvGP(gv) = 0;