Small memory leak in execute.c of ECPG driver

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Small memory leak in execute.c of ECPG driver
Date: 2015-02-03 06:58:56
Message-ID: CAB7nPqSqBaaYf5sg2wBdko=ZO-CR5HOa0fjB-1XAqedyQG8+uA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

In exactly 3 places of the ECPG driver (for numeric, for interval and
for date), we do something as follows:
/* Allocation of mallocedval */
if (!(mallocedval = ecpg_strdup("array [", lineno)))
return false;

for (element = 0; element < var->arrsize; element++)
{
int result;

ptr = stuff_alloc();
if (!ptr)
return false; <= Leak here of mallocedval

It happens that if the allocation done within this for loop fails we
leak mallocedval that was previously allocated. Attached is a patch to
fix this issue spotted by Coverity.
Regards
--
Michael

Attachment Content-Type Size
0001-Fix-memory-leak-in-ecpg-driver.patch application/x-patch 1.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2015-02-03 07:25:35 Re: Missing markup in pg_receivexlog.sgml
Previous Message Ashutosh Bapat 2015-02-03 06:32:04 Re: ExplainModifyTarget doesn't work as expected