If the passed in target rv for Perl_newSVrv() was already a reference
Nicholas Clark [Sat, 1 Apr 2006 23:34:10 +0000 (23:34 +0000)]
to something, it would leak the reference count on that thing.

p4raw-id: //depot/perl@27668

sv.c

diff --git a/sv.c b/sv.c
index 3eb5c32..c1dcf76 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -7688,9 +7688,11 @@ Perl_newSVrv(pTHX_ SV *rv, const char *classname)
        sv_clear(rv);
        SvFLAGS(rv) = 0;
        SvREFCNT(rv) = refcnt;
-    }
 
-    if (SvTYPE(rv) < SVt_RV)
+       sv_upgrade(rv, SVt_RV);
+    } else if (SvROK(rv)) {
+       SvREFCNT_dec(SvRV(rv));
+    } else if (SvTYPE(rv) < SVt_RV)
        sv_upgrade(rv, SVt_RV);
     else if (SvTYPE(rv) > SVt_RV) {
        SvPV_free(rv);