Re: Fixing memory leak in pg_upgrade

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Tatsuo Ishii <ishii(at)postgresql(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Fixing memory leak in pg_upgrade
Date: 2015-01-09 17:27:59
Message-ID: 20150109172759.GB26812@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jan 9, 2015 at 11:34:24AM -0500, Tom Lane wrote:
> Tatsuo Ishii <ishii(at)postgresql(dot)org> writes:
> > According to Coverity, there's a memory leak bug in transfer_all_new_dbs().
>
> It's pretty difficult to get excited about that; how many table-free
> databases is pg_upgrade likely to see in one run? But surely we could
> just move the pg_free call to after the if-block.

I have fixed this with the attached, applied patch. I thought malloc(0)
would return null, but our src/common pg_malloc() has:

/* Avoid unportable behavior of malloc(0) */
if (size == 0)
size = 1;

so some memory is allocated, and has to be freed. I looked at avoiding
the call to gen_db_file_maps() for old_db->rel_arr.nrels == 0, but there
are checks in there comparing the old/new relation counts, so it can't
be skipped. I also removed the unnecessary memory initialization.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

Attachment Content-Type Size
diff text/plain 1.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Aaron Botsis 2015-01-09 17:57:31 Re: Patch: [BUGS] BUG #12320: json parsing with embedded double quotes
Previous Message Stephen Frost 2015-01-09 17:24:20 Re: Parallel Seq Scan