xmlMemSetup should not be used even in module inialization. #545

Closed
obache opened this Issue Oct 6, 2011 · 6 comments

Comments

Projects
None yet
3 participants

obache commented Oct 6, 2011

xmlMemSetup() is used in Init_nokogiri() of ext/nokogiri/nokogiri.c, except MacRuby.
But xmlMemSetup has to be called before any other libxml routines, so I feel it should not be used in ext library.

For example, I want to use Ruby/RSVG (a part of Ruby-GNOME2) together with Nokogiri:
require "rsvg2"
require "nokogiri"

With just above two lines, it always crash for me, because librsvg-2.0 is using libxml-2.0 internally.

Owner

flavorjones commented Oct 7, 2011

Greetings!

When I run the above two lines, I cannot reproduce this issue. I am running:

ruby: 
  engine: mri
  version: 1.8.7
  description: ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
  platform: x86_64-linux
libxml: 
  loaded: 2.7.8
  binding: extension
  compiled: 2.7.8
nokogiri: 1.5.0

as well as rsvg2 (1.0.3).

Can you please provide more information about your environment to help me reproduce this issue?

obache commented Oct 8, 2011

I'm using on NetBSD-5.1 with ruby-1.9.2.
As far as I remember, it is probably not happened with ruby-1.8.7.

I heard that it is not happened with Linux fortunately, but also reproducible with FreeBSD.

Owner

flavorjones commented Feb 20, 2012

Still can't reproduce with 1.9.2 or 1.9.3. Can you provide any other help to reproduce this?

obache commented Feb 22, 2012

As said before, you cannot reproduce it with Linux fortunately.

Now, it will be disabled if MACRUBY' is defined, why?
I guess that it is not macruby specific, i.e. depend on OS,and maybe it must be killed with APPLE.

Just bumped into it,
this is a serious issue actually and could be reproduced.

To reproduce it use any other module that uses libxml from a native (non-ruby) thread. If ruby_xmalloc starts garbage collection from a non-ruby thread, the app terminates.

ruby_xmalloc -> (possible) garbage_collect_with_gvl -> exit(EXIT_FAILURE);

From the Ruby 1.9.3-p327 source code gc.c (715 - 717 are the lines that executed):

703 static int
704 garbage_collect_with_gvl(rb_objspace_t *objspace)
705 {
706     if (dont_gc) return TRUE;
707     if (ruby_thread_has_gvl_p()) {
708     return garbage_collect(objspace);
709     }
710     else {
711     if (ruby_native_thread_p()) {
712         return (int)(VALUE)rb_thread_call_with_gvl(gc_with_gvl, (void *)objspace);
713     }
714     else {
715         /* no ruby thread */
716         fprintf(stderr, "[FATAL] failed to allocate memory\n");
717         exit(EXIT_FAILURE);
718     }
719     }
720 }

We use async-vips for image manipulation that uses VIPS library invoking libxml from native (non-ruby) threads.

Are there any reasons you override standard memory-management routines via xmlMemSetup?

Owner

flavorjones commented Feb 16, 2016

Closing, pending a test case that reproduces the reported error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment