On Sat, Nov 24, 2012 at 10:44 PM, Robert Buck <lists / ruby-forum.com> wrote:
> Would someone have an idea of how to approach this, what could possibly
> be going on? I have been at this for three days now and I don't see any
> bug on my part.

I had a similar problem. I fixed it by preventing deallocation from
being called at the program termination.

static int in_finalizer = 0;

static void at_exit_func(VALUE val)
{
    in_finalizer = 1;
}

static void cleanup_func(void *ptr)
{
    if (in_finalizer) {
        /* Do nothing.
         * Resources are freed at the program termination.
        */
        return;
    }
    ... deallocate ptr ...
}

...
   obj = Data_Wrap_Struct(klass, mark_func, cleanup_func, ptr);
...

void
Init_xxx()
{
    rb_set_end_proc(at_exit_func, Qnil);
    ...
}