Problem with Memory Leak

From: Pete Kay <petedao(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Problem with Memory Leak
Date: 2010-03-26 02:40:45
Message-ID: 7aa8bd9d1003251940w5e2abe93t22f67b8cb2c63e7f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

I am having memory leaking problem and here is the result shown from valgrind:

==1706== 1,270 bytes in 5 blocks are still reachable in loss record 353 of 426
==1706== at 0x4C20809: malloc (vg_replace_malloc.c:149)
==1706== by 0x5D3F431: strdup (in /lib64/libc-2.5.so)
==1706== by 0x109484E0: PQsendQuery (in /usr/lib64/libpq.so.5.2)

Here is my source code:

static PGresult *get_pg_result(char *sql) {

PGresult *res=NULL;
PGresult *final_res=NULL;
PGconn* conn = NULL;

int ret = 0;

db_con_t* connection_node = get_connection();


if (connection_node == NULL) {
free(sql);
return NULL;
}


conn = connection_node->conn;
if (PQstatus(conn) != CONNECTION_OK){
PQfinish(conn);
return NULL;
}

ret = PQsendQuery(conn, sql);
if (1 != ret) {


switch_safe_free(sql);
release_connection(connection_node);
return NULL;
}

while ((res = PQgetResult(conn))) {

final_res = res;
}





free(sql);
return final_res;
}

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-03-26 02:54:46 Re: Problem with Memory Leak
Previous Message Hitoshi Harada 2010-03-26 02:06:07 Re: Re: [GENERAL] question (or feature-request): over ( partition by ... order by LIMIT N)