summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Dubois <jand@activestate.com>2000-08-17 11:31:55 -0700
committerJarkko Hietaniemi <jhi@iki.fi>2000-08-18 02:08:42 +0000
commit0199fce9e831d70af0aeef6c5962dc695c3c246f (patch)
tree591066d88034d2d4af4e9b86bd851175b8baf6b3
parente1ca407b4adcd5a31e0df6bc6b8955a291235650 (diff)
downloadperl-0199fce9e831d70af0aeef6c5962dc695c3c246f.tar.gz
newSVrv() memory leak
Message-ID: <l64ppsggaiuc4t6msm45iqohmhpjblb4qf@4ax.com> p4raw-id: //depot/perl@6687
-rw-r--r--sv.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/sv.c b/sv.c
index 9e77330c68..f065084b5e 100644
--- a/sv.c
+++ b/sv.c
@@ -5534,8 +5534,23 @@ Perl_newSVrv(pTHX_ SV *rv, const char *classname)
SV_CHECK_THINKFIRST(rv);
SvAMAGIC_off(rv);
+ if (SvTYPE(rv) >= SVt_PVMG) {
+ U32 refcnt = SvREFCNT(rv);
+ SvREFCNT(rv) = 0;
+ sv_clear(rv);
+ SvFLAGS(rv) = 0;
+ SvREFCNT(rv) = refcnt;
+ }
+
if (SvTYPE(rv) < SVt_RV)
- sv_upgrade(rv, SVt_RV);
+ sv_upgrade(rv, SVt_RV);
+ else if (SvTYPE(rv) > SVt_RV) {
+ (void)SvOOK_off(rv);
+ if (SvPVX(rv) && SvLEN(rv))
+ Safefree(SvPVX(rv));
+ SvCUR_set(rv, 0);
+ SvLEN_set(rv, 0);
+ }
(void)SvOK_off(rv);
SvRV(rv) = sv;