Skip Menu |

This queue is for tickets about the Net-SSH2 CPAN distribution.

Report information
The Basics
Id: 23930
Status: resolved
Priority: 0/
Queue: Net-SSH2

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

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



Subject: "Free to wrong pool ... " error on Win32
On Win32, perl 5.8.8, libssh2-0.14, Net-SSH2-0.09, the "free(auth);" in the net_ss_auth_list() function produces a "Free to wrong pool ..." (fatal) error. One way of fixing this problem is to simply comment out that line of code. But I'm not so sure that is the correct fix. (Does that so-called "fix" create the potential for a memory leak ?) I'd be interested to get some feedback on this as I *really* don't know what the appropriate course of action is. I note that one of the 'if' blocks in net_ss_auth_password() also contains similar code ... I haven't tested to see whether that results in the same error. Cheers, Rob
On Thu Dec 14 06:44:16 2006, SISYPHUS wrote: Show quoted text
> On Win32, perl 5.8.8, libssh2-0.14, Net-SSH2-0.09, the "free(auth);" > in the net_ss_auth_list() function produces a "Free to wrong
pool ..." Show quoted text
> (fatal) error. One way of fixing this problem is to simply comment
out Show quoted text
> that line of code. But I'm not so sure that is the correct fix.
(Does Show quoted text
> that so-called "fix" create the potential for a memory leak ?) > > I'd be interested to get some feedback on this as I *really* don't > know what the appropriate course of action is. > > I note that one of the 'if' blocks in net_ss_auth_password() also > contains similar code ... I haven't tested to see whether that
results Show quoted text
> in the same error. > > Cheers, > Rob
Seems to me that the same problem *does* occur with net_ss_auth_password. Just so there's no doubt, here's a diff on the XS file I eventually used, run against the XS file that ships with the Net-SSH2-0.09 source: --- SSH2.xs_old 2006-09-02 12:09:16.000000000 +1000 +++ SSH2.xs 2006-12-15 16:04:36.000000000 +1100 @@ -754,7 +754,7 @@ count = split_comma(sp, auth); else PUSHs(sv_2mortal(newSVpv(auth, 0))); - free(auth); + //free(auth); XSRETURN(count); void @@ -781,7 +781,7 @@ if (!password || !SvPOK(password)) { char* auth = libssh2_userauth_list(ss->session, pv_username, len_username); - free(auth); + //free(auth); XSRETURN_IV(!auth && libssh2_userauth_authenticated(ss- Show quoted text
>session));
} Again, I stress that I don't know if that's the correct fix. Cheers, Rob
From: cg2v [...] andrew.cmu.edu
On Fri Dec 15 00:20:55 2006, SISYPHUS wrote: Show quoted text
> On Thu Dec 14 06:44:16 2006, SISYPHUS wrote:
> > On Win32, perl 5.8.8, libssh2-0.14, Net-SSH2-0.09, the "free(auth);" > > in the net_ss_auth_list() function produces a "Free to wrong
> pool ..."
> > (fatal) error. One way of fixing this problem is to simply comment
> out
> > that line of code. But I'm not so sure that is the correct fix.
> (Does
> > that so-called "fix" create the potential for a memory leak ?)
(note: I'm not the maintainer of any of this software) My limited win32 experience suggests this happened because libssh2's dll and perl.exe were linked against different MSVC runtime libraries. libssh2 has support for allowing the application to provide the memory management functions, but Net-SSH2 doesn't seem to do this. I believe the following patch will make this error go away, but I have not done any testing, certainly not on win32. --- SSH2.xs.orig 2007-01-13 02:16:55.000000000 -0500 +++ SSH2.xs 2007-01-13 02:17:17.000000000 -0500 @@ -529,7 +529,7 @@ Newz(0/*id*/, RETVAL, 1, SSH2); if (RETVAL) { RETVAL->session = libssh2_session_init_ex( - NULL/*allocfunc*/, NULL/*freefunc*/, NULL/*reallocfunc*/, RETVAL); + malloc, free, realloc, RETVAL); } if (!RETVAL || !RETVAL->session) { Safefree(RETVAL); It would probably be proper to use safemalloc, safefree and saferealloc instead of the raw ANSI C functions, but SSH2.xs does not seem to use them consistently.
Subject: Re: [rt.cpan.org #23930] "Free to wrong pool ... " error on Win32
Date: Sun, 14 Jan 2007 11:54:05 +1100
To: <bug-Net-SSH2 [...] rt.cpan.org>
From: "Sisyphus" <sisyphus1 [...] optusnet.com.au>
Show quoted text
----- Original Message ----- From: "cg2v@andrew.cmu.edu via RT" <bug-Net-SSH2@rt.cpan.org> To: <SISYPHUS@cpan.org> Sent: Saturday, January 13, 2007 6:24 PM Subject: [rt.cpan.org #23930] "Free to wrong pool ... " error on Win32 . .
> > My limited win32 experience suggests this happened because libssh2's dll > and perl.exe were linked against different MSVC runtime libraries.
I built the libssh2 library myself using (the MinGW port of) the gcc compiler. And the perl that I'm running was also built (by me) using the same compiler. So, both libssh2.a (it's a static build) and perl.exe should be linked against the same msvc runtime library. . .
> I believe > the following patch will make this error go away, but I have not done > any testing, certainly not on win32. > > --- SSH2.xs.orig 2007-01-13 02:16:55.000000000 -0500 > +++ SSH2.xs 2007-01-13 02:17:17.000000000 -0500 > @@ -529,7 +529,7 @@ > Newz(0/*id*/, RETVAL, 1, SSH2); > if (RETVAL) { > RETVAL->session = libssh2_session_init_ex( > - NULL/*allocfunc*/, NULL/*freefunc*/, NULL/*reallocfunc*/, > RETVAL); > + malloc, free, realloc, RETVAL); > } > if (!RETVAL || !RETVAL->session) { > Safefree(RETVAL); >
I tried that patch but it won't compile: SSH2.xs: In function `XS_Net__SSH2_new': SSH2.xs:532: error: `PerlMem_malloc' undeclared (first use in this function) SSH2.xs:532: error: (Each undeclared identifier is reported only once SSH2.xs:532: error: for each function it appears in.) SSH2.xs:532: error: `PerlMem_free' undeclared (first use in this function) SSH2.xs:532: error: `PerlMem_realloc' undeclared (first use in this function) dmake: Error code 129, while making 'SSH2.o' Not sure where to go from there ... but I'm quite happy to try out any suggestions. Thanks for the reply
Should be fixed in 0.10: the libssh2 allocation callbacks are using Perl_malloc/Perl_realloc/Perl_mfree, and the bare malloc/frees in the code have also been replaced with the Perl versions.