Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phXs9-00025Z-GF for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Mar 2023 15:38:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1phXs8-0001WK-7s for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Mar 2023 15:38:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phXs7-0001WB-VV for pgsql-bugs@lists.postgresql.org; Wed, 29 Mar 2023 15:37:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phXs5-0005ik-9x for pgsql-bugs@lists.postgresql.org; Wed, 29 Mar 2023 15:37:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 32TFbrvr3990136; Wed, 29 Mar 2023 11:37:54 -0400 From: Tom Lane To: Pavel Borisov cc: Alexander Lakhin , pgsql-bugs@lists.postgresql.org, kyzevan23@mail.ru Subject: Re: BUG #16329: Valgrind detects an invalid read when building a gist index with buffering In-reply-to: References: <16329-7a6aa9b6fa1118a1@postgresql.org> <3dda6945-c147-5afc-7720-38ec6848dafa@gmail.com> <10261.1588705157@sss.pgh.pa.us> Comments: In-reply-to Pavel Borisov message dated "Mon, 02 Nov 2020 20:55:14 +0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3990134.1680104273.1@sss.pgh.pa.us> Date: Wed, 29 Mar 2023 11:37:53 -0400 Message-ID: <3990135.1680104273@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Pavel Borisov writes: > So I think that the patch by Alexander will do the thing. I also added some > comments to the code and removed extra context reset in gistBuildCallback > (which is already done level down) to make things clear. My apologies for having let this slip through the cracks. I think I'd wanted to understand why the committed version of the GiST index tests doesn't expose the problem, and I never got time to study that. I still haven't tracked it down, but the proposed patch seems clearly safe so I've gone ahead and pushed it. I did use Alexander's original code change that just moved the totals-incrementing. It looks to me like gistProcessEmptyingQueue is not guaranteed to reach the context reset, and I'd rather have an extra reset than miss one. (No-op context resets are cheap.) regards, tom lane