Re: Clang 3.3 Analyzer Results

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: Peter Geoghegan <pg(at)heroku(dot)com>, "noloader(at)gmail(dot)com" <noloader(at)gmail(dot)com>, Tomas Vondra <tv(at)fuzzy(dot)cz>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Clang 3.3 Analyzer Results
Date: 2013-11-12 17:00:01
Message-ID: 8303.1384275601@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Kevin Grittner <kgrittn(at)ymail(dot)com> writes:
> Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:
>> Memory Error
>> Double free: 1
>> Memory leak: 1

> These both seemed legitimate to me. Patch attached. Any
> objections to applying it? I realize the memory leak is a tiny one
> in the regression testing code, so it could never amount to enough
> to matter; but it seems worth fixing just to avoid noise in code
> analyzers.

The logic, if you can call it that, in streamutil.c makes my head hurt.
I think it needs more work than what you did here --- for one thing,
the free(password) call results in values[i] becoming a dangling pointer
to freed memory, and it's not exactly obvious that that pointer will get
overwritten again before it's used.

Moreover, although the apparent intention of the dbpassword static state
is to allow a password to be saved and reused across calls, it kinda looks
like that's broken by the odd choice to make dbgetpassword also static.
At the very least that choice makes it a lot harder to analyze what will
happen in calls after the first.

I think the looping to get a password here should be thrown out and
rewritten from scratch, or at least cribbed from someplace with less
contorted logic.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message GRIFFITHS H.P. 2013-11-12 18:07:32 Re: Cannot import logs from csv
Previous Message Kevin Grittner 2013-11-12 16:41:01 Re: Clang 3.3 Analyzer Results

Browse pgsql-hackers by date

  From Date Subject
Next Message Kohei KaiGai 2013-11-12 17:12:21 Re: What's needed for cache-only table scan?
Previous Message Andres Freund 2013-11-12 16:55:38 Re: Errors on missing pg_subtrans/ files with 9.3