Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TOvtv-0002by-OM for pgsql-bugs@postgresql.org; Thu, 18 Oct 2012 19:37:03 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TOvtp-0006sL-Ox for pgsql-bugs@postgresql.org; Thu, 18 Oct 2012 19:37:03 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id A03712A60F; Thu, 18 Oct 2012 12:36:53 -0700 (PDT) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 936D2B03D8; Thu, 18 Oct 2012 12:36:53 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id C2617C1A53; Thu, 18 Oct 2012 12:35:48 -0700 (PDT) X-Virus-Scanned: amavisd-new at zcs-prod-ext-mta-2.vmware.com Received: from zcs-prod-ext-mta-2.vmware.com ([127.0.0.1]) by localhost (zcs-prod-ext-mta-2.vmware.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id xCg_LhhUmNxe; Thu, 18 Oct 2012 12:35:48 -0700 (PDT) Received: from [192.168.1.101] (unknown [10.113.62.14]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTPSA id 6522BC1A4A; Thu, 18 Oct 2012 12:35:47 -0700 (PDT) Message-ID: <50805A52.6050009@vmware.com> Date: Thu, 18 Oct 2012 22:36:50 +0300 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.7) Gecko/20120922 Icedove/10.0.7 MIME-Version: 1.0 To: Alvaro Herrera CC: Dave Vitek , Tom Lane , Pg Bugs Subject: Re: Fwd: race in pg_ctl start -w References: <5076F626.2090404@grammatech.com> <5076FF23.6020704@iki.fi> <22107.1349976592@sss.pgh.pa.us> <50771713.8000908@vmware.com> <25454.1349984162@sss.pgh.pa.us> <507BC402.40807@vmware.com> <508052F6.20803@grammatech.com> <20121018191529.GM3763@alvh.no-ip.org> In-Reply-To: <20121018191529.GM3763@alvh.no-ip.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -7.3 (-------) X-Archive-Number: 201210/186 X-Sequence-Number: 34486 On 18.10.2012 22:15, Alvaro Herrera wrote: > Dave Vitek wrote: > >> Heikki, >> >> It's happy about the overruns. It did flag an issue where the file >> descriptor can leak when the various early returns get taken. > > This is a common problem with static analysers; they don't realise we > don't care about the leaked resource because the program is shortly > going to terminate anyway. We (used to?) have plenty of false positives > in initdb as reported in the Coverity scanner, for example. Actually, this was a real leak. I should've put close() calls to the cases where the file is empty, or fstat() fails. It doesn't matter when the function is called only once, but in the "pg_ctl start -w" case it's called repeatedly to poll for postmaster startup. Fixed, and I also changed it to not return the last line if it doesn't end in a newline, per Tom's suggestion. - Heikki