Re: memory leak

From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: "Michael P(dot) Soulier" <michael_soulier(at)mitel(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: memory leak
Date: 2012-01-10 19:06:35
Message-ID: CA+U5nMJZdRwvXs8Uzk7xkz0BArtvxO_f9rsUZdYJuZ2TswG5-A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jan 10, 2012 at 6:48 PM, Michael P. Soulier
<michael_soulier(at)mitel(dot)com> wrote:

>    res = PQexec(conn, "BEGIN");
>    if (PQresultStatus(res) != PGRES_COMMAND_OK)
>    {
>        fprintf(stderr, "DB: BEGIN command failed: %s", PQerrorMessage(conn));
>        PQclear(res);
>        exit_nicely(conn);
>    }
>
>    res = PQexec(conn, commandbuf);
>    if (PQresultStatus(res) != PGRES_COMMAND_OK)
>    {
>        fprintf(stderr, "DB: UPDATE command failed: %s", PQerrorMessage(conn));
>        PQclear(res);
>        exit_nicely(conn);
>    }
>
>    /* end the transaction */
>    res = PQexec(conn, "END");
>    PQclear(res);

You're missing 2 PQclear() calls on success.

http://www.postgresql.org/docs/devel/static/libpq-exec.html#LIBPQ-EXEC-MAIN

PQclear

Frees the storage associated with a PGresult. Every command result
should be freed via PQclear when it is no longer needed.

void PQclear(PGresult *res);

You can keep a PGresult object around for as long as you need it;
it does not go away when you issue a new command, nor even if you
close the connection. To get rid of it, you must call PQclear. Failure
to do this will result in memory leaks in your application.

--
 Simon Riggs                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

In response to

  • memory leak at 2012-01-10 18:48:58 from Michael P. Soulier

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael P. Soulier 2012-01-10 19:17:58 Re: memory leak
Previous Message Michael P. Soulier 2012-01-10 18:48:58 memory leak