From: Jesse Luehrs Date: Sat, 13 Nov 2010 19:03:30 +0000 (-0600) Subject: don't leak memory on hv_store fail X-Git-Tag: 0.14~28 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1d6c978bb7d895ccd3ee8d9c1c2fad0d627af732;p=gitmo%2FPackage-Stash-XS.git don't leak memory on hv_store fail --- diff --git a/Stash.xs b/Stash.xs index 72ee898..d0a9a70 100644 --- a/Stash.xs +++ b/Stash.xs @@ -271,17 +271,23 @@ new(class, package_name) PREINIT: HV *instance; HV *namespace; + SV *nsref; CODE: if (!SvPOK(package_name)) croak("The constructor argument must be the name of a package"); instance = newHV(); - if (!hv_store(instance, "name", 4, SvREFCNT_inc_simple_NN(package_name), 0)) + if (!hv_store(instance, "name", 4, SvREFCNT_inc_simple_NN(package_name), 0)) { + SvREFCNT_dec(package_name); croak("Couldn't initialize the 'name' key, hv_store failed"); + } namespace = gv_stashpv(SvPV_nolen(package_name), GV_ADD); - if (!hv_store(instance, "namespace", 9, newRV_inc((SV*)namespace), 0)) + nsref = newRV_inc((SV*)namespace); + if (!hv_store(instance, "namespace", 9, nsref, 0)) { + SvREFCNT_dec(nsref); croak("Couldn't initialize the 'namespace' key, hv_store failed"); + } RETVAL = sv_bless(newRV_noinc((SV*)instance), gv_stashpv(class, 0)); OUTPUT: