Skip Menu |

This queue is for tickets about the Clone CPAN distribution.

Report information
The Basics
Id: 27671
Status: resolved
Priority: 0/
Queue: Clone

People
Owner: Nobody in particular
Requestors: RUZ [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.23
Fixed in: (no value)



Subject: memory leak when using weak references
Hi. I'm too tired to describe the problem, so I hope a test and draft of a patch will help you to figure out what's wrong and fix it in the right way. -- Best regards, Ruslan.
Subject: clone_memory_leak.pl
use strict; use warnings; package foo; sub DESTROY { print "del $_[0]\n" } package main; use Clone qw(clone); use Scalar::Util qw(weaken isweak); { my $a = bless { }, 'foo'; print "new $a\n"; my $b = bless { r => $a }, 'foo'; print "new $b\n"; $a->{'r'} = $b; weaken($b->{'r'}); my $c = clone($a); print "new $c\n"; } print "The End.\n";
Subject: clone_memory_leak_draft.patch
Только в Clone-0.23-my/: blib Только в Clone-0.23-my/: Clone.bs Только в Clone-0.23-my/: Clone.c Только в Clone-0.23-my/: Clone.o diff -ru Clone-0.23/Clone.xs Clone-0.23-my/Clone.xs --- Clone-0.23/Clone.xs 2007-04-20 09:40:27.000000000 +0400 +++ Clone-0.23-my/Clone.xs 2007-06-21 04:12:43.000000000 +0400 @@ -123,7 +123,7 @@ { SV *clone = ref; SV **seen = NULL; - UV visible = (SvREFCNT(ref) > 1); + UV visible = (SvREFCNT(ref) > 1) || (SvMAGICAL(ref) && mg_find(ref, '<')); int magic_ref = 0; TRACEME(("ref = 0x%x(%d)\n", ref, SvREFCNT(ref))); @@ -226,6 +226,7 @@ for (mg = SvMAGIC(ref); mg; mg = mg->mg_moremagic) { SV *obj = (SV *) NULL; + int magic_clone = 1; /* we don't want to clone a qr (regexp) object */ /* there are probably other types as well ... */ TRACEME(("magic type: %c\n", mg->mg_type)); @@ -241,6 +242,7 @@ continue; break; case '<': /* PERL_MAGIC_backref */ + magic_clone = 0; continue; break; default: @@ -251,6 +253,7 @@ } magic_ref++; /* this is plain old magic, so do the same thing */ + if (magic_clone) sv_magic(clone, obj, mg->mg_type, @@ -280,6 +283,9 @@ { sv_bless (clone, SvSTASH (SvRV (ref))); } + if (SvWEAKREF(ref)) { + sv_rvweaken(clone); + } } TRACEME(("clone = 0x%x(%d)\n", clone, SvREFCNT(clone))); Только в Clone-0.23-my/: Makefile Только в Clone-0.23-my/: Makefile.old diff -ru Clone-0.23/Makefile.PL Clone-0.23-my/Makefile.PL --- Clone-0.23/Makefile.PL 2006-10-08 07:37:20.000000000 +0400 +++ Clone-0.23-my/Makefile.PL 2007-06-21 04:04:54.000000000 +0400 @@ -6,7 +6,7 @@ 'NAME' => 'Clone', 'VERSION_FROM' => 'Clone.pm', # finds $VERSION 'LIBS' => [''], # e.g., '-lm' - 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' +# 'DEFINE' => '-DDEBUG_CLONE', # e.g., '-DHAVE_SOMETHING' 'INC' => '', # e.g., '-I/usr/include/other' # 'OPTIMIZE' => '-g', # e.g., '-I/usr/include/other' 'OPTIMIZE' => '-O3', # e.g., '-I/usr/include/other' Только в Clone-0.23-my/: pm_to_blib
Any updates on this? This bug cause quite big leak in production. we don't use this patch as I'm not sure it's 100% correct. What do you need to fix and release new version? Tests? Description? Something else? On Wed Jun 20 20:45:40 2007, RUZ wrote: Show quoted text
> Hi. > > I'm too tired to describe the problem, so I hope a test and draft of a > patch will help you to figure out what's wrong and fix it in the right
way. -- Best regards, Ruslan.
This ticket can be resolved as the latest version have no this leak. On Tue Jun 26 16:14:10 2007, RUZ wrote: Show quoted text
> Any updates on this? This bug cause quite big leak in production. we > don't use this patch as I'm not sure it's 100% correct. > > What do you need to fix and release new version? Tests? Description? > Something else? > > On Wed Jun 20 20:45:40 2007, RUZ wrote:
> > Hi. > > > > I'm too tired to describe the problem, so I hope a test and draft of a > > patch will help you to figure out what's wrong and fix it in the right
> way. >
-- Best regards, Ruslan.
This was resolved a while back in 0.28.