diff options
author | Ilya Zakharevich <ilya@math.berkeley.edu> | 1999-02-07 10:07:27 -0500 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-02-07 23:26:04 +0000 |
commit | 4327152a8da835b489f2314100b405920cc614ea (patch) | |
tree | 7482bd3f3e844d5ca29fab8fecd5d7f0301d5a37 | |
parent | 1ae175c8d48ec3f9bff4739583753d9b46939a5f (diff) | |
download | perl-4327152a8da835b489f2314100b405920cc614ea.tar.gz |
patch for change#2822, done right; add PERL_OBJECT stuff; regen headers
Message-ID: <19990207150726.A571@monk.mps.ohio-state.edu>
Subject: Re: fixing memory leaks in REx compilation
p4raw-link: @2822 on //depot/perl: 34184a49c8a0771dbea73b3f0519126fd5b22c2f
p4raw-id: //depot/perl@2826
-rw-r--r-- | embed.h | 1 | ||||
-rwxr-xr-x | embed.pl | 1 | ||||
-rw-r--r-- | objXSUB.h | 2 | ||||
-rw-r--r-- | proto.h | 1 | ||||
-rw-r--r-- | regcomp.c | 14 | ||||
-rw-r--r-- | regcomp.h | 8 | ||||
-rw-r--r-- | regexec.c | 6 |
7 files changed, 25 insertions, 8 deletions
@@ -1080,6 +1080,7 @@ #define ck_subr CPerlObj::Perl_ck_subr #define ck_svconst CPerlObj::Perl_ck_svconst #define ck_trunc CPerlObj::Perl_ck_trunc +#define clear_re CPerlObj::Perl_clear_re #define condpair_magic CPerlObj::Perl_condpair_magic #define convert CPerlObj::Perl_convert #define croak CPerlObj::Perl_croak @@ -356,6 +356,7 @@ my @staticfuncs = qw( add_data re_croak2 regpposixcc + clear_re regmatch regrepeat regrepeat_hard @@ -971,6 +971,8 @@ #define ck_svconst pPerl->Perl_ck_svconst #undef ck_trunc #define ck_trunc pPerl->Perl_ck_trunc +#undef clear_re +#define clear_re pPerl->Perl_clear_re #undef condpair_magic #define condpair_magic pPerl->Perl_condpair_magic #undef convert @@ -869,6 +869,7 @@ I32 study_chunk _((regnode **scanp, I32 *deltap, regnode *last, scan_data_t *dat I32 add_data _((I32 n, char *s)); void re_croak2 _((const char* pat1,const char* pat2,...)) __attribute__((noreturn)); char* regpposixcc _((I32 value)); +void clear_re _((void *r)); I32 regmatch _((regnode *prog)); I32 regrepeat _((regnode *p, I32 max)); I32 regrepeat_hard _((regnode *p, I32 max, I32 *lp)); @@ -147,6 +147,7 @@ static char* regwhite _((char *, char *)); static char* nextchar _((void)); static void re_croak2 _((const char* pat1,const char* pat2,...)) __attribute__((noreturn)); static char* regpposixcc _((I32 value)); +static void clear_re _((void *r)); #endif /* Length of a variant. */ @@ -207,6 +208,12 @@ static scan_data_t zero_scan_data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; #define CHR_DIST(a,b) (UTF ? utf8_distance(a,b) : a - b) STATIC void +clear_re(void *r) +{ + ReREFCNT_dec((regexp *)r); +} + +STATIC void scan_commit(scan_data_t *data) { dTHR; @@ -868,7 +875,12 @@ pregcomp(char *exp, char *xend, PMOP *pm) r->prelen = xend - exp; r->precomp = PL_regprecomp; r->subbeg = r->subbase = NULL; - r->nparens = PL_regnpar - 1; /* set early to validate backrefs */ + r->nparens = PL_regnpar - 1; /* set early to validate backrefs */ + + r->substrs = 0; /* Useful during FAIL. */ + r->startp = 0; /* Useful during FAIL. */ + r->endp = 0; /* Useful during FAIL. */ + PL_regcomp_rx = r; /* Second pass: emit code. */ @@ -188,15 +188,15 @@ struct regnode_2 { #define FAIL(m) \ STMT_START { \ - /*if (!SIZE_ONLY) \ - ReREFCNT_dec(PL_regcomp_rx);*/ \ + if (!SIZE_ONLY) \ + SAVEDESTRUCTOR(clear_re,(void*)PL_regcomp_rx); \ croak ("/%.127s/: %s", PL_regprecomp,m); \ } STMT_END #define FAIL2(pat,m) \ STMT_START { \ - /*if (!SIZE_ONLY) \ - ReREFCNT_dec(PL_regcomp_rx);*/ \ + if (!SIZE_ONLY) \ + SAVEDESTRUCTOR(clear_re,(void*)PL_regcomp_rx); \ re_croak2("/%.127s/: ",pat,PL_regprecomp,m); \ } STMT_END @@ -329,7 +329,7 @@ regexec_flags(register regexp *prog, char *stringarg, register char *strend, /* Check validity of program. */ if (UCHARAT(prog->program) != REG_MAGIC) { - FAIL("corrupted regexp program"); + croak("corrupted regexp program"); } PL_reg_flags = 0; @@ -2445,7 +2445,7 @@ regmatch(regnode *prog) default: PerlIO_printf(PerlIO_stderr(), "%lx %d\n", (unsigned long)scan, OP(scan)); - FAIL("regexp memory corruption"); + croak("regexp memory corruption"); } scan = next; } @@ -2454,7 +2454,7 @@ regmatch(regnode *prog) * We get here only if there's trouble -- normally "case END" is * the terminating point. */ - FAIL("corrupted regexp pointers"); + croak("corrupted regexp pointers"); /*NOTREACHED*/ sayNO; |