Small memory leak in execute.c of ECPG driver - Mailing list pgsql-hackers

From Michael Paquier
Subject Small memory leak in execute.c of ECPG driver
Date
Msg-id CAB7nPqSqBaaYf5sg2wBdko=ZO-CR5HOa0fjB-1XAqedyQG8+uA@mail.gmail.com
Whole thread Raw
Responses Re: Small memory leak in execute.c of ECPG driver  (Heikki Linnakangas <hlinnakangas@vmware.com>)
List 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

pgsql-hackers by date:

Previous
From: Ashutosh Bapat
Date:
Subject: Re: ExplainModifyTarget doesn't work as expected
Next
From: Heikki Linnakangas
Date:
Subject: Re: Missing markup in pg_receivexlog.sgml