From: | Heikki Linnakangas <hlinnakangas(at)vmware(dot)com> |
---|---|
To: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Small memory leak in execute.c of ECPG driver |
Date: | 2015-02-03 08:35:02 |
Message-ID: | 54D08836.1070003@vmware.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 02/03/2015 08:58 AM, Michael Paquier wrote:
> 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.
I think there are more similar leaks nearby. After the first hunk,
there's another if-check with "return false" that also leaks
mallocedval. Right after the two other hunks, if the ecpg_realloc fails,
we again leak mallocedval.
I wonder why Coverity didn't warn about those? Maybe it would've, after
fixing the first ones.
- Heikki
From | Date | Subject | |
---|---|---|---|
Next Message | Heikki Linnakangas | 2015-02-03 08:38:28 | Re: Missing markup in pg_receivexlog.sgml |
Previous Message | Michael Paquier | 2015-02-03 08:27:32 | Re: Missing markup in pg_receivexlog.sgml |