7.3.4: memory leak in fe-exec.c:279 (realloc) - Mailing list pgsql-bugs

From Max Kellermann
Subject 7.3.4: memory leak in fe-exec.c:279 (realloc)
Date
Msg-id 20031002101604.GA16519@duempel.org
Whole thread Raw
Responses Re: 7.3.4: memory leak in fe-exec.c:279 (realloc)
List 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

pgsql-bugs by date:

Previous
From: Richard Ellis
Date:
Subject: Re: is this my date problem
Next
From: Tom Lane
Date:
Subject: Re: is this my date problem