I test the mysql_real_query API, I just loop to execute Sql syntax ,like 'UPDATE ** SET **' there is a leak memory bug occur. when I use 'top' to check the bug, I find the system 'used memory' option will always growing until the system or process crush. but 'mysqld' and 'testsql' processes's %MEM option has not increase, System free memory look like disappear. I try to force kill the 'testsql' process but the memory still be used and can not be release. Why? Please help me. -
int ThreadExeSQL(MYSQL* lpSQLConn, char * sql, int iLen)
-
{
-
-
if (mysql_real_query(lpSQLConn, sql, iLen))
-
{
-
MYSQL_RES* lpGetSQLRes = mysql_store_result(lpSQLConn);
-
mysql_free_result(lpGetSQLRes);
-
return -1;
-
}
-
-
//mysql_errno(lpSQLConn);
-
//mysql_error(lpSQLConn);
-
-
MYSQL_RES* lpGetSQLRes = mysql_store_result(lpSQLConn);
-
mysql_free_result(lpGetSQLRes); // release sql memory
-
-
return 0; // success
-
}
-
-
void* ThreadSQL_HexWrite(void* lpGet)
-
{
-
-
LPThreadParam getParam = (LPThreadParam)lpGet;
-
-
MYSQL* lpSQLConn = (MYSQL*)&getParam->lpSQLConn;
-
int iThreadIdx = getParam->iThreadIdx;
-
-
printf("ID:%d\n", iThreadIdx);
-
-
mysql_thread_init();
-
-
lpSQLConn = mysql_init(NULL);
-
-
-
if (!mysql_real_connect(lpSQLConn, g_host_name, g_user_name, g_password, g_db_name, g_db_port, NULL, 0))
-
{
-
ThreadSQLError(lpSQLConn, NULL);
-
return;
-
}
-
else
-
{
-
printf("mysql_real_connect OK!\n");
-
}
-
-
-
for (int i = 0; i < 1000000; i++)
-
{
-
-
char lpCmdStr[8192] = "\0";
-
sprintf(lpCmdStr, "update %s set %s=0x%d where id=%d\0", "tb_Data", "Info", i, 1);
-
-
if (ThreadExeSQL(lpSQLConn, (char*)lpCmdStr, strlen(lpCmdStr)))
-
{
-
MySQLError getError = ThreadSQLError(lpSQLConn, NULL);
-
HandleMySqlError(getError);
-
-
return; //erroe
-
}
-
else
-
{
-
printf("ok. ");
-
}
-
-
usleep(1000 * 10);
-
}
-
-
mysql_close(lpSQLConn);
-
-
mysql_thread_end();
-
-
-
printf("ThreadSQL_HexWrite OK!\n");
-
}
-
-
-
MYSQL* g_MySQLConnList[100];
-
-
void main()
-
{
-
-
if (mysql_library_init(0, NULL, NULL))
-
{
-
printf("could not initialize MySQL client library\n");
-
exit(1);
-
}
-
-
-
int thread_num = 1;
-
-
//while (true)
-
{
-
pthread_t *pTh = new pthread_t[thread_num];
-
-
-
for (int i = 0; i < thread_num; i++)
-
{
-
-
LPThreadParam lpSetParam = new ThreadParam;
-
lpSetParam->lpSQLConn = (MYSQL*)&g_MySQLConnList[i];
-
lpSetParam->iThreadIdx = i;
-
-
printf("---create thread idx:%d\n", i);
-
if (0 != pthread_create(&pTh[i], NULL, ThreadSQL_HexWrite, lpSetParam))
-
{
-
printf("pthread_create failed\n");
-
continue;
-
}
-
}
-
-
for (int i = 0; i < thread_num; i++)
-
{
-
pthread_join(pTh[i], NULL);
-
}
-
-
delete[] pTh;
-
}
-
-
mysql_library_end();
-
-
printf("All Done!\n");
-
-
}
-
1 1889 -
for (int i = 0; i < 1000000; i++)
-
{
-
......
-
if (ThreadExeSQL...)
-
{
-
......
-
continue; // this line change to continue; code copy with a little mistake.
-
}
-
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kayra Otaner |
last post by:
Hi all,
I want to get your opinions on how to increase available/free memory and
performance on a heavy volume database server.
I have MySQL 4.0.13 running on RH 7.2 replicated to another RH...
|
by: kayra |
last post by:
Hi all,
I want to get your opinions on how to increase available/free memory and
performance on a heavy volume database server.
I have MySQL 4.0.13 running on RH 7.2 replicated to another RH...
|
by: Brett B |
last post by:
I just installed mysql on linux. If I open a terminal, su to root,
then type "mysql", I am able to connect to the server and run my
queries.
If I exit out of su so that I am my own id (baisley)...
|
by: Bob Bedford |
last post by:
We have no access to a mysql NG on my provider's server, so we ask here:
We have a long query (long in text) with a UNION between 2 select.
We have been informed that some times the query...
|
by: astroboy |
last post by:
How do I detect which object cause memory leak????
Thx
|
by: linux |
last post by:
Sorry if this is a really dumb question. I am trying to connect to our
remote MySQL server (which is running just fine). I have a perl script
which
worked just fine on my other Fedora 4 box (all...
|
by: saran |
last post by:
I am having a problem with MySQL consuming a lot of memory and
eventually throwing an Out of Memory error and restarting itself. The
symptoms are that swap usage continues to rise until some...
|
by: dan |
last post by:
Hi all,
I have a question about flash-memory lifespan.
My database consists of 1 table, the table has 50 fields of 10 bytes
each, thus each record will have 500bytes. There are 1000 records in...
|
by: Andreas Schmitt |
last post by:
Hi,
I recently worked on an open source project and tried to make on of the
arrays they are using dynamically allocated to get rid of the max size.
I used the realloc instead of the usual C++...
|
by: markodilore |
last post by:
Hey Guys, you helped me once when I tryied to create a database : "Access denied for user ''@'localhost' ". On my Mac OS 10.4, I had no problem creating database and modifying it from the terminal....
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |