Rb_raise and memory

In re.c(make_regexp):

    rp = ALLOC(Regexp);
    MEMZERO((char *)rp, Regexp, 1);
    rp->buffer = ALLOC_N(char, 16);
    rp->allocated = 16;
    rp->fastmap = ALLOC_N(char, 256);
    if (flags) {
        rp->options = flags;
    }
    err = re_compile_pattern(s, len, rp);

    if (err != NULL) {
        rb_reg_raise(s, len, err, 0);
    }
    return rp;

As rb_raise is implemented with longjmp, won't this leed to
memory-leaks? I have code that works similar to this, so I'd really
like to know, so that I can clean up before I call rb_raise if
necessary,
  nikolai

···

--
::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}

Hi,

···

In message "Re: rb_raise and memory" on Thu, 10 Mar 2005 06:08:30 +0900, Nikolai Weibull <mailing-lists.ruby-talk@rawuncut.elitemail.org> writes:

As rb_raise is implemented with longjmp, won't this leed to
memory-leaks? I have code that works similar to this, so I'd really
like to know, so that I can clean up before I call rb_raise if
necessary,

It's leaking. Thank you for finding it.

              matz.

* Yukihiro Matsumoto (Mar 10, 2005 00:20):

> As rb_raise is implemented with longjmp, won't this leed to
> memory-leaks? I have code that works similar to this, so I'd really
> like to know, so that I can clean up before I call rb_raise if
> necessary,

It's leaking. Thank you for finding it.

No problem. Is there a simple workaround (other than explicitly
calling free before rb_raise), such as registering the address with the
GC? One would have to wrap it in a VALUE it seems, which isn't
great...

Anyway, I'm just curious if there's a nice way of solving this without
explicit frees,
  nikolai

···

--
::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}

Hi,

···

In message "Re: rb_raise and memory" on Thu, 10 Mar 2005 08:25:49 +0900, Nikolai Weibull <mailing-lists.ruby-talk@rawuncut.elitemail.org> writes:

It's leaking. Thank you for finding it.

No problem. Is there a simple workaround (other than explicitly
calling free before rb_raise), such as registering the address with the
GC? One would have to wrap it in a VALUE it seems, which isn't
great...

There's no way for Ruby GC to handle non-VALUE data. The only
solution I can think of is moving to Boehm GC, which might be an
overkill.

              matz.