From: Jesse Luehrs Date: Sat, 13 Nov 2010 15:02:46 +0000 (-0600) Subject: actually fix the memory leak in new() X-Git-Tag: 0.14~39 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ce38493ccaffb0867e6d891b041a03de0feb97a7;p=gitmo%2FPackage-Stash-XS.git actually fix the memory leak in new() --- diff --git a/Stash.xs b/Stash.xs index b2a744b..ac83c6d 100644 --- a/Stash.xs +++ b/Stash.xs @@ -274,11 +274,11 @@ new(class, package_name) if (!SvPOK(package_name)) croak("The constructor argument must be the name of a package"); - instance = newHV(); + instance = (HV*)sv_2mortal((SV*)newHV()); - hv_store(instance, "name", 4, package_name, 0); + hv_store(instance, "name", 4, SvREFCNT_inc(package_name), 0); namespace = gv_stashpv(SvPV_nolen(package_name), GV_ADD); - hv_store(instance, "namespace", 9, newRV_noinc((SV*)namespace), 0); + hv_store(instance, "namespace", 9, newRV_inc((SV*)namespace), 0); RETVAL = sv_bless(newRV_inc((SV*)instance), gv_stashpv(class, 0)); OUTPUT: