also don't leak the instance on error
Jesse Luehrs [Sat, 13 Nov 2010 19:16:28 +0000 (13:16 -0600)]
Stash.xs

index d0a9a70..12931d6 100644 (file)
--- a/Stash.xs
+++ b/Stash.xs
@@ -280,12 +280,14 @@ new(class, package_name)
 
     if (!hv_store(instance, "name", 4, SvREFCNT_inc_simple_NN(package_name), 0)) {
         SvREFCNT_dec(package_name);
+        SvREFCNT_dec(instance);
         croak("Couldn't initialize the 'name' key, hv_store failed");
     }
     namespace = gv_stashpv(SvPV_nolen(package_name), GV_ADD);
     nsref = newRV_inc((SV*)namespace);
     if (!hv_store(instance, "namespace", 9, nsref, 0)) {
         SvREFCNT_dec(nsref);
+        SvREFCNT_dec(instance);
         croak("Couldn't initialize the 'namespace' key, hv_store failed");
     }