summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Zakharevich <ilya@math.berkeley.edu>1999-02-07 10:07:27 -0500
committerGurusamy Sarathy <gsar@cpan.org>1999-02-07 23:26:04 +0000
commit4327152a8da835b489f2314100b405920cc614ea (patch)
tree7482bd3f3e844d5ca29fab8fecd5d7f0301d5a37
parent1ae175c8d48ec3f9bff4739583753d9b46939a5f (diff)
downloadperl-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.h1
-rwxr-xr-xembed.pl1
-rw-r--r--objXSUB.h2
-rw-r--r--proto.h1
-rw-r--r--regcomp.c14
-rw-r--r--regcomp.h8
-rw-r--r--regexec.c6
7 files changed, 25 insertions, 8 deletions
diff --git a/embed.h b/embed.h
index ef311c69df..78c28e2970 100644
--- a/embed.h
+++ b/embed.h
@@ -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
diff --git a/embed.pl b/embed.pl
index 46df6c32b1..3aabd9f609 100755
--- a/embed.pl
+++ b/embed.pl
@@ -356,6 +356,7 @@ my @staticfuncs = qw(
add_data
re_croak2
regpposixcc
+ clear_re
regmatch
regrepeat
regrepeat_hard
diff --git a/objXSUB.h b/objXSUB.h
index 9c8460fc4e..71aa21108a 100644
--- a/objXSUB.h
+++ b/objXSUB.h
@@ -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
diff --git a/proto.h b/proto.h
index e536733c41..93517d2e70 100644
--- a/proto.h
+++ b/proto.h
@@ -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));
diff --git a/regcomp.c b/regcomp.c
index f78388b827..91f9d7b5fc 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -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. */
diff --git a/regcomp.h b/regcomp.h
index 1a139c5b77..1538f8ab58 100644
--- a/regcomp.h
+++ b/regcomp.h
@@ -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
diff --git a/regexec.c b/regexec.c
index f7210a0529..f53567e9a6 100644
--- a/regexec.c
+++ b/regexec.c
@@ -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;