7.3.4: memory leak in fe-exec.c:279 (realloc)

Lists: pgsql-bugs
From: Max Kellermann <max(at)linuxtag(dot)org>
To: pgsql-bugs(at)postgresql(dot)org
Subject: 7.3.4: memory leak in fe-exec.c:279 (realloc)
Date: 2003-10-02 10:16:04
Message-ID: 20031002101604.GA16519@duempel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Hi,

I have found a memory leak in PostgreSQL 7.3.4,
src/interfaces/libpq/fe-exec.c line 279:

buffer = realloc(buffer, buflen);
if (buffer == NULL)
return NULL;

The realloc manpage says:

"If realloc() fails the original block is left untouched - it is
not freed or moved."

i.e. "buffer" is not freed if there is not enough memory for
realloc. The code should be like this:

temp_buffer = realloc(buffer, buflen);
if (temp_buffer == NULL) {
free(buffer);
return NULL;
}
buffer = temp_buffer;

Regards,
Max Kellermann


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Max Kellermann <max(at)linuxtag(dot)org>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: 7.3.4: memory leak in fe-exec.c:279 (realloc)
Date: 2003-10-02 14:46:36
Message-ID: 27163.1065105996@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Max Kellermann <max(at)linuxtag(dot)org> writes:
> I have found a memory leak in PostgreSQL 7.3.4,
> src/interfaces/libpq/fe-exec.c line 279:

This appears to have been dealt with already (although realistically,
it would be an extremely brain-dead realloc that could ever fail here,
since the block is being shrunk not grown).

regards, tom lane