Skip Menu |

This queue is for tickets about the Sys-Hostname-FQDN CPAN distribution.

Report information
The Basics
Id: 91162
Status: resolved
Worked: 15 min
Priority: 0/
Queue: Sys-Hostname-FQDN

People
Owner: michael [...] bizsystems.com
Requestors: jiro [...] cpan.org
Cc:
AdminCc:

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



Subject: Memory leak in XS functions
The following script detects any memory leaks. === use strict; use Test::More; use Test::LeakTrace; use Sys::Hostname::FQDN; no_leaks_ok { Sys::Hostname::FQDN::asciihostinfo; Sys::Hostname::FQDN::gethostinfo; Sys::Hostname::FQDN::inet_ntoa("127.0.0.1"); Sys::Hostname::FQDN::inet_aton("localhost"); Sys::Hostname::FQDN::fqdn; Sys::Hostname::FQDN::short; }; done_testing; === The following patch fixes the problems. === --- FQDN.xs.orig 2013-12-04 10:52:31.000000000 +0900 +++ FQDN.xs 2013-12-04 10:52:38.000000000 +0900 @@ -70,8 +70,7 @@ ST(0) = &PL_sv_undef; } else { - out = sv_newmortal(); - out = newSVpv(local_name,0); + out = sv_2mortal(newSVpv(local_name,0)); ST(0) = out; } XSRETURN(1); @@ -88,8 +87,7 @@ } naddr; PPCODE: naddr.addr = (SvPV(netaddr, len)); - out = sv_newmortal(); - out = newSVpv(inet_ntoa(*naddr.inadr),0); + out = sv_2mortal(newSVpv(inet_ntoa(*naddr.inadr),0)); ST(0) = out; XSRETURN(1); @@ -108,7 +106,6 @@ PPCODE: dq = (unsigned char *)(SvPV(dotquad, len)); inet_aton((char *)dq,&myaddr); - out = sv_newmortal(); - out = newSVpv((char *)&myaddr.s_addr,4); + out = sv_2mortal(newSVpv((char *)&myaddr.s_addr,4)); ST(0) = out; XSRETURN(1); === Regards, Jiro Nishiguchi <jiro@cpan.org>
On Tue Dec 03 21:22:43 2013, JIRO wrote: Show quoted text
> The following script detects any memory leaks. > > === > use strict; > use Test::More; > use Test::LeakTrace; > use Sys::Hostname::FQDN; > > no_leaks_ok { > Sys::Hostname::FQDN::asciihostinfo; > Sys::Hostname::FQDN::gethostinfo; > Sys::Hostname::FQDN::inet_ntoa("127.0.0.1"); > Sys::Hostname::FQDN::inet_aton("localhost"); > Sys::Hostname::FQDN::fqdn; > Sys::Hostname::FQDN::short; > }; > done_testing; > === > > The following patch fixes the problems. > > === > --- FQDN.xs.orig 2013-12-04 10:52:31.000000000 +0900 > +++ FQDN.xs 2013-12-04 10:52:38.000000000 +0900 > @@ -70,8 +70,7 @@ > ST(0) = &PL_sv_undef; > } > else { > - out = sv_newmortal(); > - out = newSVpv(local_name,0); > + out = sv_2mortal(newSVpv(local_name,0)); > ST(0) = out; > } > XSRETURN(1); > @@ -88,8 +87,7 @@ > } naddr; > PPCODE: > naddr.addr = (SvPV(netaddr, len)); > - out = sv_newmortal(); > - out = newSVpv(inet_ntoa(*naddr.inadr),0); > + out = sv_2mortal(newSVpv(inet_ntoa(*naddr.inadr),0)); > ST(0) = out; > XSRETURN(1); > > @@ -108,7 +106,6 @@ > PPCODE: > dq = (unsigned char *)(SvPV(dotquad, len)); > inet_aton((char *)dq,&myaddr); > - out = sv_newmortal(); > - out = newSVpv((char *)&myaddr.s_addr,4); > + out = sv_2mortal(newSVpv((char *)&myaddr.s_addr,4)); > ST(0) = out; > XSRETURN(1); > === > > Regards, > > Jiro Nishiguchi <jiro@cpan.org>
Thanks for the patch, fixed in 0.12