The following program leaks memory, anybody knows why?
void f(void * arg)
{
char * dbName ="xxxxxxx";
char * lanName = "goosexxx";
PGconn * conn = NULL;
conn = PQsetdb( lanName,
NULL,
NULL,
NULL,
dbName
);
if ( PQstatus(conn) == CONNECTION_BAD )
{
if( DebugIndicator )
{
fprintf(stderr,
"Connection to [dbName=%s lanName=%s threadId=%d]"
" failed.\n", dbName, lanName, (int) pthread_self() );
fprintf(stderr, "%s", PQerrorMessage(conn));
}
PQfinish(conn);
conn=NULL;
}
PQfinish(conn);
poll(0,0,100);
pthread_exit(NULL);
}
int main()
{
pthread_t pd;
while(1)
{
pthread_create(&pd, NULL, f, (void *) NULL);
pthread_join(pd, NULL);
}
return 0;
}
/**************************/
This only happens with threads, if I do not use threads and simply call f() in the loop the program does not leak.
Also, if I comment out PostgreSQL stuff from f() and call it through thread, there is no problem!
Looks like there is a problem with Red Hat 7.1 or PostgreSQL!
Anybody knows why?
void f(void * arg)
{
char * dbName ="xxxxxxx";
char * lanName = "goosexxx";
PGconn * conn = NULL;
conn = PQsetdb( lanName,
NULL,
NULL,
NULL,
dbName
);
if ( PQstatus(conn) == CONNECTION_BAD )
{
if( DebugIndicator )
{
fprintf(stderr,
"Connection to [dbName=%s lanName=%s threadId=%d]"
" failed.\n", dbName, lanName, (int) pthread_self() );
fprintf(stderr, "%s", PQerrorMessage(conn));
}
PQfinish(conn);
conn=NULL;
}
PQfinish(conn);
poll(0,0,100);
pthread_exit(NULL);
}
int main()
{
pthread_t pd;
while(1)
{
pthread_create(&pd, NULL, f, (void *) NULL);
pthread_join(pd, NULL);
}
return 0;
}
/**************************/
This only happens with threads, if I do not use threads and simply call f() in the loop the program does not leak.
Also, if I comment out PostgreSQL stuff from f() and call it through thread, there is no problem!
Looks like there is a problem with Red Hat 7.1 or PostgreSQL!
Anybody knows why?