From: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com> |
---|---|
To: | Madhurima Das <madhurima(dot)das(at)gmail(dot)com> |
Cc: | PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: memory leak while trying to update/alter column in postgresql |
Date: | 2014-07-05 11:57:22 |
Message-ID: | CAB7nPqQ6W5ZiyD8cibTXLWmx3e3j5+A-5s8noeQTSCpixF2hjQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sat, Jul 5, 2014 at 11:06 AM, Madhurima Das <madhurima(dot)das(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Augori | 2014-07-05 11:58:45 | Re: Failed to build transaction for opengeo-server |
Previous Message | Martijn van Oosterhout | 2014-07-05 08:35:52 | Re: Random-looking primary keys in the range 100000..999999 |