[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

rb_raise and memory

Nikolai Weibull

3/9/2005 9:09:00 PM

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);}


5 Answers

Yukihiro Matsumoto

3/9/2005 11:15:00 PM

0

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.


Nikolai Weibull

3/9/2005 11:26:00 PM

0

* 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);}


Yukihiro Matsumoto

3/10/2005

0

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.


Charles Mills

3/10/2005 5:25:00 PM

0

Nikolai Weibull wrote:
> * 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,

One technique that typically prevents this is using an alloc function.
For example:

struct my_array {
long len;
VALUE *ptr;
};

#define GetMyArray(obj, var) /* get the struct my_array from obj */

VALUE
my_array_alloc(VALUE klass)
{
struct my_array *a = ALLOC(struct my_array);
a->len = 0;
a->ptr = 0;
/* if data wrap struct has a memory error (which is very unlikely)
* you get a memory leak. */
return Data_Wrap_Struct(...)
}

VALUE
my_array_init(VALUE array, VALUE length)
{
long len;
struct my_array *a;
GetMyArray(array, a);
assert(a->ptr == 0 && a->len == 0);
len = NUM2LONG(length);
a->ptr = ALLOC_N(VALUE, len);
a->len = len;
return array;
}

So above the ruby object is allocated and registered with the GC before
you start allocating memory for the fields (ptr in this case) of struct
my_array.
This helps prevent errors which occur during initialization from
creating memory leaks.

-Charlie

Brad Guth

9/22/2009 5:50:00 PM

0

On Sep 21, 9:32 pm, Warhol <mol...@hotmail.com> wrote:
> On Sep 22, 5:38 am, BDK <TopSh...@sanity.com> wrote:
>
>
>
> > In article <a700b186-40f8-44e7-81e8-35fb4be0f14f@
> > 2g2000prl.googlegroups.com>, bradg...@gmail.com says...
>
> > > On Sep 21, 4:58 pm, BDK <TopSh...@sanity.com> wrote:
> > > > In article <fb40133e-db79-4d55-8193-
> > > > f11771187...@d34g2000vbm.googlegroups.com>, mol...@hotmail.com says....
>
> > > > > On Sep 22, 12:15 am, BradGuth <bradg...@gmail.com> wrote:
> > > > > > On Sep 21, 10:04 am, BDK <TopSh...@sanity.com> wrote:
>
> > > > > > > In article <f7d2c21e-0e13-47a3-832d-
> > > > > > > ee74e281d...@u16g2000pru.googlegroups.com>, bradg...@gmail.com says...
>
> > > > > > > > On Sep 21, 5:55 am, drahcir <justrichardsmu...@gmail.com> wrote:
> > > > > > > > > On Sep 15, 1:23 pm, BradGuth <bradg...@gmail.com> wrote:
>
> > > > > > > > > > On Sep 15, 10:15 am, drahcir <justrichardsmu...@gmail..com> wrote:
>
> > > > > > > > > > > On Sep 14, 10:20 am, BradGuth <bradg...@gmail.com> wrote:
>
> > > > > > > > > > > > On Sep 11, 8:04 am, Warhol <mol...@hotmail.com> wrote:
>
> > > > > > > > > > > > > A Mossad truck bomb that killed 242 marines  in 1983 Beirut
>
> > > > > > > > > > > > > The 1983 Bombing Of The Marine Barracks In Beirut..http://judicial-inc.biz/Beirut_fals...
>
> > > > > > > > > > > > > Revelations:
>
> > > > > > > > > > > > > "The Jewish people as a whole will be its own Messiah. It will attain
> > > > > > > > > > > > > world domination by the dissolution of other races...and by the
> > > > > > > > > > > > > establishment of a world republic in which everywhere the Jews will
> > > > > > > > > > > > > exercise the privilege of citizenship. In this New World Order the
> > > > > > > > > > > > > Children of Israel...will furnish all the leaders without encountering
> > > > > > > > > > > > > opposition..." (Karl Marx in a letter to Baruch Levy, quoted in Review
> > > > > > > > > > > > > de Paris, June 1, 1928, p. 574)
>
> > > > > > > > > > > > > Pentagon Analyst Dr. Beter's:
>
> > > > > > > > > > > > > November 3, 1982 "...I reported that the Marines had been sent there
> > > > > > > > > > > > > to become the focus of a major incident. The Mossad is to arrange for
> > > > > > > > > > > > > a number of our Marines to be killed in an incident that will be
> > > > > > > > > > > > > blamed on the Arabs! This will be used to inflame American public
> > > > > > > > > > > > > opinion to help lead us into war, including ultimately nuclear war."
>
> > > > > > > > > > > > It seems that our false flag efforts are better than most.  Only hope
> > > > > > > > > > > > is that such disclosures don't get you and the few others like
> > > > > > > > > > > > yourself dead.
>
> > > > > > > > > > > >  ~ BG
>
> > > > > > > > > > > LOL! Brad, if nothing else, you have a vivid imagination.
>
> > > > > > > > > > Among many considerations, the mutually perpetrated cold-war was not
> > > > > > > > > > "vivid imagination".
>
> > > > > > > > > Um, yes, but it seems you must have forgotten the topic, which was
> > > > > > > > > your (perhaps drug-induced), hilarious Mossad dream.
>
> > > > > > > > > > What else are you in kosher denial about?
>
> > > > > > > > > Fairies, genies, leprechauns, and the possibility you are sane.
>
> > > > > > > > > > Are you also pretending to be an Atheist?
>
> > > > > > > > > Why do you care?
>
> > > > > > > > Because unlike yourself, I'm not a Zionist/Jew (aka pretend-Atheist)
> > > > > > > > that cares not about anyone outside of my faith-based cabal.
>
> > > > > > > > What's the matter this time?  Don't you want investigative reporting?
>
> > > > > > > >  ~ BG
>
> > > > > > > I would like some reporter to do an expose on you.
>
> > > > > > > Maybe titled:
>
> > > > > > > Brad Guth, uberkook!
>
> > > > > > > Or:
>
> > > > > > > Portrait of a kook's kook: Brad Guth, AKA Guthball.
>
> > > > > > > --
>
> > > > > > > BDK..
> > > > > > > Leader of the nonexistent paid shills.
> > > > > > > Non Jew Jew Club founding member.
> > > > > > > Former number one Kook Magnet, title passed to Iarnrod.
>
> > > > > > Unlike yourself and all other Zionist Nazis, I exist as a for real
> > > > > > person.
>
> > > > > > So, where's Warhol?
>
> > > > > >  ~ BG
>
> > > > > I am Home... under protection of this Saints...
> > > > >http://zombietime.com/mohammed_image_archive/misc_mo/scotusnfr...
>
> > > > > as seen at US Supreme Court building...
>
> > > > > Charlemagne - Mohammed - Justinian
>
> > > > See Brad, your little loon buddy is back. Now you can go back to Venus.
> > > > --
>
> > > > BDK..
> > > > Leader of the nonexistent paid shills.
> > > > Non Jew Jew Club founding member.
> > > > Former number one Kook Magnet, title passed to Iarnrod.
>
> > > This is good news, because if you can't manage to kill Warhol, perhaps
> > > there's a chance that you can't get to others you'd like nothing
> > > better than to terminate, as required for your faith-based global
> > > domination.
>
> > >  ~ BG
>
> > Why would I, or anyone here on usenet want to kill Wormhole, or any of
> > you other kooks? There are so many reasons not to do it.
>
> > 1. It might make you a martyr to the other loons, getting them all
> > agitated, and the world doesn't need another agitated kook.
>
> > 2. It would be a tragedy to lose the laughs you guys create.
>
> > 3. And the main reason, it's just not worth the money it would cost to
> > hire the hitters.
>
> > --
>
> Who murdered millions and got away with it!http://newsfromthewest.blogspot.com/2007/11/jewish-murderer......
>
> Jewish murderers...
>
> Can you disprove it ?
>
> Or are you dismayed that unlike in other fora, this topic won't just
> 'disappear' because it contains inconvenient truths ?
>
> As a yid, do you ever step back and look at the information ?
>
> Or have you been trained to simply complain about it and to rely on
> the old 'anti semitism' card ?
>
> Is being in Usenet helping you to combat the programming and to look
> at the information ?
>
> Or do you tell yourself ' it's all lies, it's all lies, my ears and
> eyes are closed to this because it's all lies and someone should make
> it go away ' ?

Our Usenet pretend-Atheists and Yids wear those thick rimmed tunnel
vision glasses and special kosher ear plugs that each automatically
filters out the best available truths, as well as somehow eliminating
remorse.

~ BG