Re: memory leak

Поиск
Список
Период
Сортировка
От Simon Riggs
Тема Re: memory leak
Дата
Msg-id CA+U5nMJZdRwvXs8Uzk7xkz0BArtvxO_f9rsUZdYJuZ2TswG5-A@mail.gmail.com
обсуждение исходный текст
Ответ на memory leak  ("Michael P. Soulier" <michael_soulier@mitel.com>)
Ответы Re: memory leak  ("Michael P. Soulier" <michael_soulier@mitel.com>)
Список pgsql-general
On Tue, Jan 10, 2012 at 6:48 PM, Michael P. Soulier
<michael_soulier@mitel.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

В списке pgsql-general по дате отправления:

Предыдущее
От: "Michael P. Soulier"
Дата:
Сообщение: memory leak
Следующее
От: "Michael P. Soulier"
Дата:
Сообщение: Re: memory leak