Re: memory leak while trying to update/alter column in postgresql - Mailing list pgsql-general

From Michael Paquier
Subject Re: memory leak while trying to update/alter column in postgresql
Date
Msg-id CAB7nPqQ6W5ZiyD8cibTXLWmx3e3j5+A-5s8noeQTSCpixF2hjQ@mail.gmail.com
Whole thread Raw
In response to memory leak while trying to update/alter column in postgresql  (Madhurima Das <madhurima.das@gmail.com>)
List pgsql-general
On Sat, Jul 5, 2014 at 11:06 AM, Madhurima Das <madhurima.das@gmail.com> wrote:
> int main()
> {
> PGconn *conn;
>        PGresult *res;
> int i=0,nFields=0,row=0,col=0;
>
> conn = PQconnectdb("dbname=test1 host=localhost user=postgres
> password=yyy");
>    if(PQstatus(conn) == CONNECTION_BAD)
>    {
> fprintf(stderr, "Connection to database \"%s\" failed.\n",
> PQerrorMessage(conn));
> fprintf(stderr, "%s", PQerrorMessage(conn));
> exit_nicely(conn);
> }
>
> res = PQexec(conn, "IF COL_LENGTH('xxx','comment') IS NULL");
Call to PQclear is missing here or before the next call to PQexec.

> if(res)
> res = PQexec(conn, "ALTER TABLE xxx ADD comment VARCHAR(500)");
>    else
> res = PQexec(conn, "UPDATE TABLE xxx ADD comment VARCHAR(500)");
Same here.

> res = PQexec(conn, "IF COL_LENGTH('xxx','id') IS NULL");
Same here.

> if(res)
> res = PQexec(conn, "ALTER TABLE xxx ADD id VARCHAR(50)");
>    else
> res = PQexec(conn, "UPDATE TABLE xxx ADD id VARCHAR(50)");
Same here.

>   res = PQexec(conn, "SELECT * FROM xxx");
> if((!res) || (PQresultStatus(res) != PGRES_TUPLES_OK))
> {
> fprintf(stderr, "SELECT command did not return tuples properly\n");
> PQclear(res);
> }
>
> PQclear(res);
> PQfinish(conn);
>
> return 0;
> }
Btw, there is a lot of code duplication...
--
Michael


pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Random-looking primary keys in the range 100000..999999
Next
From: Augori
Date:
Subject: Re: Failed to build transaction for opengeo-server