Skip Menu |

This queue is for tickets about the Inline-Struct CPAN distribution.

Report information
The Basics
Id: 99091
Status: resolved
Worked: 1 hour (60 min)
Priority: 0/
Queue: Inline-Struct

People
Owner: ETJ [...] cpan.org
Requestors: heinz.knutzen [...] gmail.com
Cc:
AdminCc:

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



Subject: Wrong REFCNT with Inline::Struct
Date: Tue, 23 Sep 2014 21:24:32 +0200
To: bug-Inline-Struct [...] rt.cpan.org
From: Heinz Knutzen <heinz.knutzen [...] gmail.com>
I think that REFCNT isn't handled correctly in Inline::Struct. REFCNT is set to 1 when the struct is created. That is ok. But REFCNT is incremented each time a struct member is changed. Hence the REFCNT isn't 1 when the last reference to the struct is removed. Therefore the memory of struct isn't reclaimed. Example program: ============================================ use strict; use warnings; use Inline C => <<'END', STRUCTS => 1; struct Foo { int inum; double dnum; char *str; }; END my $o = Inline::Struct::Foo->new(); my ($id) = keys %Inline::Struct::Foo::_map_; print "REFCNT: $Inline::Struct::Foo::_map_{$id}->{REFCNT}\n"; $o->inum(10); print "REFCNT: $Inline::Struct::Foo::_map_{$id}->{REFCNT}\n"; $o->dnum(3.1415); print "REFCNT: $Inline::Struct::Foo::_map_{$id}->{REFCNT}\n"; $o->str('Wazzup?'); print "REFCNT: $Inline::Struct::Foo::_map_{$id}->{REFCNT}\n"; $o->inum(11); print "REFCNT: $Inline::Struct::Foo::_map_{$id}->{REFCNT}\n"; $o = undef; ============================================ Output: REFCNT: 1 REFCNT: 2 REFCNT: 3 REFCNT: 4 REFCNT: 5 When adding this line to the DESTROY function of generated XS code: warn("DESTROY: REFCNT %d FREE %d",SvIV(refcnt), tofree); and got this additional output: DESTROY: REFCNT 5 FREE 1. DESTROY: REFCNT 4 FREE 1 during global destruction. DESTROY: REFCNT 3 FREE 1 during global destruction. DESTROY: REFCNT 2 FREE 1 during global destruction. DESTROY: REFCNT 1 FREE 1 during global destruction. Used versions: - Inline-Struct-0.10 - Perl v5.18.2
This is an awesome report, thanks! Feel like taking the one extra step and converting your demo code into a .t file? (I'm not sure if it's possible to trap warnings in global destruction, but maybe a "perl -e" with IPC::Open3 would do the trick?)
Subject: Re: [rt.cpan.org #99091] Wrong REFCNT with Inline::Struct
Date: Wed, 24 Sep 2014 22:18:25 +0200
To: bug-Inline-Struct [...] rt.cpan.org
From: Heinz Knutzen <heinz.knutzen [...] gmail.com>
Find refcnt.t attached. It tests REFCNT values. But I have no idea, if / how to patch DESTROY inside a .t file. Patch is attached separately.

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

Show quoted text
> Find refcnt.t attached. It tests REFCNT values.
You'll see that's now on the git master (with you getting the credit), thanks! Show quoted text
> But I have no idea, if / how to patch DESTROY inside a .t file.
No reason for you to try that. I'm using your other patch to track/fix this.
Now fixed in commit 4f3e20829cdd4653cebec1e5109c225229a641bb and uploaded as v0.11.
Subject: Re: [rt.cpan.org #99091] Wrong REFCNT with Inline::Struct
Date: Thu, 25 Sep 2014 22:16:30 +0200
To: bug-Inline-Struct [...] rt.cpan.org
From: Heinz Knutzen <heinz.knutzen [...] gmail.com>
The new file t/refcnt.t is missing from MANIFEST and hence missing from Inline-Struct-0.11.