You are are right. That was the case. It has a thread running in an indefinite loop, which calls mysql routines below.
//program starts
..
MYSQL *mysqlconnect(void) {
const char *s;
MYSQL *mysql;
if((mysql=mysql_init(NULL))==NULL) return NULL;
if((mysql_real_connect(mysql, DBHOST, DBUSER, DBPW, DBDB, 0, NULL, 0))==NULL) {
s=mysql_error(mysql);
report(SYSLOG, (char *) s, error_code_predescribed);
mysql_close(mysql);
return NULL;
}
else return (mysql);
}
..
//thread procedure starts
MYSQL mysql;
..
while(1) {
if((mysql=mysqlconnect)!=NULL) {
do some database operations;
}
else sleep(5);
} //while
..
//thread ends
Main {
..
}
//program ends
Because mysql pointer never gets freed it always creates a new one for each loop in thread procedure.
I copied mysqlconnect procedure content into the thread, and localize it. Then, it solved the problem.
However, I need to search some other solutions. Because I call mysqconnect almost in every procedure.
Thank you so much for your great advise.
|