pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sandro Santilli <strk@keybit.net>
To: Greg Stark <stark@mit.edu>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Craig Ringer <craig@2ndquadrant.com>
Cc: Florian Pflug <fgp@phlo.org>
Cc: PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Subject: Re: Leaking regexp_replace in 9.3.1 ? (was: [HACKERSUninterruptable regexp_replace in 9.3.1 ?)
Date: Wed, 19 Mar 2014 12:43:25 +0100
Message-ID: <20140319114325.GG4042@localhost> (raw)
In-Reply-To: <CAM-w4HNWVuNqo0d8DUNg5Ucaw6wnx7yzWv6zKnK5RRFN=_rT4Q@mail.gmail.com>
References: <D4594E29-6A28-43C0-BD33-FC3EE8A23683@phlo.org>
	<53077EED.2000907@2ndquadrant.com>
	<3663.1393002213@sss.pgh.pa.us>
	<646.1393031856@sss.pgh.pa.us>
	<20140226150113.GD9740@localhost>
	<20140318170401.GE29859@localhost>
	<32100.1395186092@sss.pgh.pa.us>
	<20140319075359.GA4042@localhost>
	<20140319085702.GF4042@localhost>
	<CAM-w4HNWVuNqo0d8DUNg5Ucaw6wnx7yzWv6zKnK5RRFN=_rT4Q@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On Wed, Mar 19, 2014 at 10:57:10AM +0000, Greg Stark wrote:
> On Wed, Mar 19, 2014 at 8:57 AM, Sandro Santilli <strk@keybit.net> wrote:
> > ==21240==    by 0x64A200: newdfa.isra.4 (rege_dfa.c:307)
> > ==21240==    by 0x64A4C3: getsubdfa (regexec.c:285)
> > ==21240==    by 0x64B80A: cdissect (regexec.c:673)
> > ==21240==    by 0x64C802: pg_regexec (regexec.c:473)
> 
> 
> It looks like a simple bug pg_regexec where it's reusing a loop
> counter "n" to mean two different things. When it goes to free all the
> subdfas it looks like the code was written based "n" still being the
> number of trees but in fact it's been reused to be the number of
> matches.

I confirm this patch fixes the leak:

inline patch 1: src/backend/regex/regexec.c (+1/-0 lines) download inline-1.patchdiff --git a/src/backend/regex/regexec.c b/src/backend/regex/regexec.c index 0edb83c..2e97662 100644 --- a/src/backend/regex/regexec.c +++ b/src/backend/regex/regexec.c @@ -259,6 +259,7 @@ pg_regexec(regex_t *re, /* clean up */ if (v->pmatch != pmatch && v->pmatch != mat) FREE(v->pmatch); + n = (size_t) v->g->ntree; for (i = 0; i < n; i++) { if (v->subdfas[i] != NULL)
--strk; -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs

view thread (8+ messages)  latest in thread

Message-ID: <20140319114325.GG4042@localhost>
Permalink:  ../20140319114325.GG4042@localhost/
Also on:    postgresql.org/message-id/20140319114325.GG4042@localhost

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: strk@keybit.net, stark@mit.edu, tgl@sss.pgh.pa.us, craig@2ndquadrant.com, fgp@phlo.org
  Subject: Re: Leaking regexp_replace in 9.3.1 ? (was: [HACKERSUninterruptable regexp_replace in 9.3.1 ?)
  In-Reply-To: <20140319114325.GG4042@localhost>
  References: <D4594E29-6A28-43C0-BD33-FC3EE8A23683@phlo.org> <53077EED.2000907@2ndquadrant.com> <3663.1393002213@sss.pgh.pa.us> <646.1393031856@sss.pgh.pa.us> <20140226150113.GD9740@localhost> <20140318170401.GE29859@localhost> <32100.1395186092@sss.pgh.pa.us> <20140319075359.GA4042@localhost> <20140319085702.GF4042@localhost> <CAM-w4HNWVuNqo0d8DUNg5Ucaw6wnx7yzWv6zKnK5RRFN=_rT4Q@mail.gmail.com> <20140319114325.GG4042@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox