A couple of weeks ago Johnathan Conley and I spent some time trying to get libxml to work better on windows. Unfortunately, we did not succeed due to the memory leaks mentioned in other threads.

However, one obvious error in the current bindings is the use of free. The bindings use Ruby's ALLOCA macro to allocate memory for various objects, but then proceed to unallocate using free instead of xfree (xfree is also provided by Ruby).

The technical reason for this is that ALLOCA and xfree create and free memory from the Ruby executable's stack. On the other hand, malloc and free in an extension create and free memory from the extension's stack. In some cases the executable's and extension's stack are one and the same thing.

But on windows they are often not. In this case, Ruby is built with VC++ 6.0 but I build the libxml bindings with VC++2005. That means that the Ruby executable and extension library use different versions of the C runtime library, and thus have different stacks. For more information see http://msdn2.microsoft.com/en-us/library/ms235460(VS.80).aspx.

The end result is that ALLOCA uses memory from the executable's stack, and then free unallocates them using the extension's stack. And of course you get segmentation faults.

The solution to this one is easy - all free's should be changed to xfree's.

Thanks,

Charlie

P.S.  - Any progress on integrating the leak patches from OpenStreetMap?

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel

Reply via email to