Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f88Er-0002DI-SA for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Apr 2018 17:48:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f88Eq-0008Br-D2 for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Apr 2018 17:48:24 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f88Eq-0008Bg-3W for pgsql-bugs@lists.postgresql.org; Mon, 16 Apr 2018 17:48:24 +0000 Received: from new1-smtp.messagingengine.com ([66.111.4.221]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f88En-0000E0-AP for pgsql-bugs@lists.postgresql.org; Mon, 16 Apr 2018 17:48:22 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 3084B1394; Mon, 16 Apr 2018 13:48:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 16 Apr 2018 13:48:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=sxznQ5opn26Ky2fRp sQ7eLjpSAJ2Q3NPRugZtgHPTh8=; b=cXYxBxU38lqAIa1U59EWkI6PZoipdedsy 5mNq64LzyB8ewUTBO6Zon13KhP/7Yrfcq1yHYwIRr6lcnX8cGbKg9t1u4j6w+Nge uMtSig/3BDY+7y+zmmZlEzLUr9VEgpChPzKGKZ2o/T6jiR06KX1C+XmIB0tv9H5N YG/RkOJ0Agcratu7Qg7bmY0Y7k/kCK1HSGxCLY76lBy+q8BLIgGfBzkgIzaWG5eR BexU8zx0iElPTUZM+SXDnibe1OlOLBc45mAFp/wV1DY/rWrf2Z16AmMoMQSBfDY7 s3/kZDqHik3eizvw8uXFMVz7QLhsFVcGCINKAz5NrXX9qRnzhZIYA== X-ME-Sender: Received: from alvin.alvh.no-ip.org (unknown [179.56.29.253]) by mail.messagingengine.com (Postfix) with ESMTPA id 6624FE443C; Mon, 16 Apr 2018 13:48:19 -0400 (EDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 8AAA37D6; Mon, 16 Apr 2018 14:48:17 -0300 (-03) Date: Mon, 16 Apr 2018 14:48:17 -0300 From: Alvaro Herrera To: Peter Geoghegan Cc: Andres Freund , "Vitaly V. Voronov" , PostgreSQL mailing lists Subject: Re: BUG #15144: *** glibc detected *** postgres: postgres smsconsole [local] SELECT: double free or corruption (!pre Message-ID: <20180416174817.3krcrdtfkiwkhj4s@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Geoghegan wrote: > On Mon, Apr 16, 2018 at 10:09 AM, Andres Freund wrote: > >> I have vague memories of somebody submitting a version of this code > >> that returned approximate answers, good enough for monitoring ... > > > > That might have been me, but I don't recall the details anymore... > > Obviously you're thinking of 6e654546fb61f62cc982d0c8f62241b3b30e7ef8. > I have a hard time imagining how that could be implicated in this hard > crash, though, except perhaps by removing something that masked the > problem in earlier versions. Yeah, I wasn't commenting on the crash itself -- just on how bad it is to let Zabbix monitor your database in this way. Maybe it *is* useful in certain situations, as Andres says, but I bet zabbix doesn't actually discriminate like that. Now, looking at the code for (i = 0; i < node->nfuncs; i++) { FunctionScanPerFuncState *fs = &node->funcstates[i]; if (fs->func_slot) ExecClearTuple(fs->func_slot); if (fs->tstore != NULL) { tuplestore_end(node->funcstates[i].tstore); fs->tstore = NULL; } and tuplestore_end does this: if (state->myfile) BufFileClose(state->myfile); without setting anything in state to NULL; so we're relying on the caller fs->tstore to null to avoid repeated tuplestore_end calls. I can't see any way for this to misbehave, but maybe the funcstate appears more than once in the PerFuncState array, and we clean it correctly the first time around and then invoke the tuplestore_end() the second time to the memory that was previously freed? I think this makes no sense unless we share FunctionScanPerFuncState elements -- do we? -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services