From: Marcus Holland-Moritz Date: Thu, 9 Mar 2006 12:54:19 +0000 (+0000) Subject: Fix a memory leak in ck_grep(), spotted by coverity: X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=03ca120dd65c92dac47010526eabc9f1009766e3;p=p5sagit%2Fp5-mst-13.2.git Fix a memory leak in ck_grep(), spotted by coverity: perl -e'eval "grep" while 1' p4raw-id: //depot/perl@27436 --- diff --git a/op.c b/op.c index 1471c2f..a6a5422 100644 --- a/op.c +++ b/op.c @@ -6444,13 +6444,13 @@ OP * Perl_ck_grep(pTHX_ OP *o) { dVAR; - LOGOP *gwop; + LOGOP *gwop = NULL; OP *kid; const OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE; I32 offset; o->op_ppaddr = PL_ppaddr[OP_GREPSTART]; - NewOp(1101, gwop, 1, LOGOP); + /* don't allocate gwop here, as we may leak it if PL_error_count > 0 */ if (o->op_flags & OPf_STACKED) { OP* k; @@ -6461,6 +6461,7 @@ Perl_ck_grep(pTHX_ OP *o) for (k = cUNOPx(kid)->op_first; k; k = k->op_next) { kid = k; } + NewOp(1101, gwop, 1, LOGOP); kid->op_next = (OP*)gwop; o->op_flags &= ~OPf_STACKED; } @@ -6477,6 +6478,8 @@ Perl_ck_grep(pTHX_ OP *o) Perl_croak(aTHX_ "panic: ck_grep"); kid = kUNOP->op_first; + if (!gwop) + NewOp(1101, gwop, 1, LOGOP); gwop->op_type = type; gwop->op_ppaddr = PL_ppaddr[type]; gwop->op_first = listkids(o);