Ok, the issue was caused by linking to both the debug and release runtime 
libraries. I had built OpenSSL in release mode but libssh was built in debug. 

Incredibly, the linker took the "strdup" function from the release runtime but 
took "free" function from "debug" runtime (or vice versa). These runtimes use 
different heaps, hence the error. Another triumph of technical excellence from 
Microsoft.

Thanks for your feedback Paulo.

- Gearoid
________________________________________
From: Murphy, Gearoid P
Sent: 15 June 2011 13:19
To: [email protected]
Subject: RE: strdup vs _strdup on Windows builds

That certainly seems related to what I'm seeing but I'm not using static 
linking anywhere, at least, not that I know of. I will rebuild ssl and libssh 
again to see if there are any configuration details which could be changed.

Thanks
 - Gearoid

________________________________
From: Paulo Panhoto [[email protected]]
Sent: 15 June 2011 12:55
To: [email protected]
Subject: Re: strdup vs _strdup on Windows builds

Hi,

I found a link that might be related to this problem:
http://connect.microsoft.com/VisualStudio/feedback/details/333868/programs-using-a-static-library-and-calling-strdup-crash

Regards,

Paulo

On Wed, Jun 15, 2011 at 6:35 AM, Murphy, Gearoid P 
<[email protected]<mailto:[email protected]>> wrote:
Hi

I've run into a heap corruption assertion whilst running the example programs 
shipped with the libhssh source. I'm building on an x64 Windows 7 VM using 
Visual Studio 2008 with libssh 0.5.0.

Debugging always traced the error to the process of freeing memory allocated 
via strdup. MSDN documentation states that strdup was deprecated from Visual 
Studio 2005 onwards. 
http://msdn.microsoft.com/en-us/library/ms235454(v=vs.80).aspx<http://msdn.microsoft.com/en-us/library/ms235454%28v=vs.80%29.aspx><http://msdn.microsoft.com/en-us/library/ms235454%28v=vs.80%29.aspx>

Unfortunately, this sort of volatility is a constant issue on Windows systems. 
Nothing like having a monopoly to compensate for brain-dead technical decisions 
;-). I was able to address the issue by refactoring the code to use _strdup 
instead of strdup but I'd rather not have to do this each time I compile a new 
build of libssh. I'd be happy to assist wherever possible but I'd like to get 
some feedback first.

Thanks
 - Gearoid






Reply via email to