develooper Front page | perl.perl5.porters | Postings from May 2009

Re: [perl.git] branch blead, updated. GitLive-blead-1218-gcda5537

From:
Nicholas Clark
Date:
May 30, 2009 07:18
Subject:
Re: [perl.git] branch blead, updated. GitLive-blead-1218-gcda5537
Message ID:
20090530141819.GJ6391@plum.flirble.org
On Sat, May 30, 2009 at 04:05:09PM +0200, Rafael Garcia-Suarez wrote:

>     Fix [RT#63110] -- two small memory leaks were introduced in 5b9c067

Oops.


> diff --git a/hv.c b/hv.c
> index a6b4448..79d1944 100644
> --- a/hv.c
> +++ b/hv.c
> @@ -1444,7 +1444,7 @@ Perl_hv_copy_hints_hv(pTHX_ HV *const ohv)
>  	while ((entry = hv_iternext_flags(ohv, 0))) {
>  	    SV *const sv = newSVsv(HeVAL(entry));
>  	    sv_magic(sv, NULL, PERL_MAGIC_hintselem,
> -		     (char *)newSVhek (HeKEY_hek(entry)), HEf_SVKEY);
> +		     (char *)sv_2mortal(newSVhek (HeKEY_hek(entry))), HEf_SVKEY);
>  	    (void)hv_store_flags(hv, HeKEY(entry), HeKLEN(entry),
>  				 sv, HeHASH(entry), HeKFLAGS(entry));
>  	}

Having now looked closely at Perl_sv_magicext(), with:

	else if (namlen == HEf_SVKEY) {
	    /* Yes, this is casting away const. This is only for the case of
	       HEf_SVKEY. I think we need to document this abberation of the
	       constness of the API, rather than making name non-const, as
	       that change propagating outwards a long way.  */
	    mg->mg_ptr = (char*)SvREFCNT_inc_simple_NN((SV *)name);
	} else

[oops, grammar error]

Whilst the reference counting implied by sv_2mortal() is correct, I don't
think that it actually needs to be a mortal. A simple SvREFCNT_dec() after
the call to sv_magic() should work.

Nicholas Clark



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About