Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WQEuE-0006Vk-Ts for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Mar 2014 11:43:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WQEuE-0007wG-8c for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Mar 2014 11:43:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WQEuD-0007w7-7a for pgsql-bugs@postgresql.org; Wed, 19 Mar 2014 11:43:33 +0000 Received: from mail-ee0-x230.google.com ([2a00:1450:4013:c00::230]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WQEu9-00025l-HC for pgsql-bugs@postgresql.org; Wed, 19 Mar 2014 11:43:32 +0000 Received: by mail-ee0-f48.google.com with SMTP id b57so5784413eek.21 for ; Wed, 19 Mar 2014 04:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=J6BQcEbqIOQAXMXQHfUroVUHkbMJxiRC9iVGjSi+7cg=; b=E5GStw1nL6mKwbsFWBysPn2HOo69X1e4vTsJ+Zwaop8XRQmwU6vruauyfrYJa5h+3T kOTtOn7DjzalM7RcroMUqi8TwiBJtk6q2YIQ3ICK5IExruZPWuCtvjGwLfyyceH5Y+hc 9qBSYJa16pDO4x9geRnVIGcJu5Kfoe4osfj8NbtdOwaUN3LPWtTXla6REGdBFKvPVLxI mRSwEdnZZuC1j5ItIxm5Tqows2tWVSxQObLAQzN0Xg343nYDw2M10BLbI1UGYjaIVlxd u1F7VHkW7Es2MjBRXGqJSa9Rc2HvHX0mKv9v7UbllK3NF5fuTTPCfrUWCl4WSSBtxoid 5O7Q== X-Received: by 10.14.207.68 with SMTP id m44mr20092693eeo.79.1395229409103; Wed, 19 Mar 2014 04:43:29 -0700 (PDT) Received: from localhost (ip-46-232-148-34.static.adsl.cheapnet.it. [46.232.148.34]) by mx.google.com with ESMTPSA id g3sm41870119eet.35.2014.03.19.04.43.27 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 19 Mar 2014 04:43:28 -0700 (PDT) Date: Wed, 19 Mar 2014 12:43:25 +0100 From: Sandro Santilli To: Greg Stark Cc: Tom Lane , Craig Ringer , Florian Pflug , PostgreSQL Bugs Subject: Re: Leaking regexp_replace in 9.3.1 ? (was: [HACKERSUninterruptable regexp_replace in 9.3.1 ?) Message-ID: <20140319114325.GG4042@localhost> References: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On Wed, Mar 19, 2014 at 10:57:10AM +0000, Greg Stark wrote: > On Wed, Mar 19, 2014 at 8:57 AM, Sandro Santilli 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: diff --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