From: nobu.nokada@... Date: 2002-08-29T00:18:49+09:00 Subject: Re: [Update] Port match to new dup, clone framework Hi, At Wed, 28 Aug 2002 23:42:53 +0900, Michal Rokos wrote: > This should fix it. :-) (I said should, but I know that nobu > will find at least 1 bug in it... :-)) You mean this? ;-) /(.*)/=~"foo"; $~.become(Regexp.allocate) will leak memory. > @@ -528,40 +529,17 @@ match_alloc() > } > > static VALUE > -match_clone(match) > - VALUE match; > +match_become(obj, orig) > + VALUE obj, orig; > { > - NEWOBJ(clone, struct RMatch); > - CLONESETUP(clone, match); > - > - clone->str = RMATCH(match)->str; > - clone->regs = 0; > - > - clone->regs = ALLOC(struct re_registers); > - clone->regs->allocated = 0; > - re_copy_registers(clone->regs, RMATCH(match)->regs); + if (obj == orig) return obj; > + RMATCH(obj)->str = RMATCH(orig)->str; + re_free_registers(RMATCH(obj)->regs); > + RMATCH(obj)->regs->allocated = 0; > + re_copy_registers(RMATCH(obj)->regs, RMATCH(orig)->regs); Or just leave allocated as is, without setting to 0. -- Nobu Nakada