Hello I've just experienced troubles with mysql_free_result() but don't know what is wrong... one of my programs has 2 simultaneous connections to MySQL and crashed when doing the mysql_free_result(), I thought it was 'cos the way I was making the program, but now I have the problem with single connection and still crashes randomly.
This is the part of of the source code, not to understand what does every function, just to illustrate, it is almost self-explanatory -------------------------------------------------------- MYCLASS dbmail; // CONNECT TO MYSQL if ( !dbmail.RealConnect(host,user,password) ) { printf("Unable to connect to %s...\n%s",host,dbmail.Error()); return 0; } // SELECT DATABASE if ( dbmail.SelectDatabase((char*)DBM_DATABASE)!=0 ) { printf("Unable to open database: %s...\n",DBM_DATABASE); dbmail.Close(); return 0; } // QUERY DATABASE // 'condition' is suplied by user ("where x=y", etc) sprintf(query_search,"SELECT address FROM DBM_ADDRESS %s",condition); if ( dbmail.RealQuery(query_search,strlen(query_search))!= 0 || !dbmail.UseResult() ) { // leaves MYSQL_RES* stored inside the class printf("*** %s\n",dbmail.Error()); fflush(stdout); dbmail.Close(); return 0; } MYSQL_ROW record; while ( (record=dbmail.FetchRow())!=NULL ) { printf("%s\n",record[0]); } //dbmail.FreeResult(); dbmail.Close(); -------------------------------------------------------- When it reaches dbmail.FreeResult() it crashes... why? I don't know, by commenting that line everything works (although possibly resources are not free). The important member functions and internals involved in the code above are these: (handler, result arrays etc are inside the class) -------------------------------------------------------- class MYCLASS { ... private: MYSQL sql_handle; MYSQL_RES *sql_result; MYSQL_ROW sql_rows; ... } MYSQL_RES* MYCLASS::UseResult (void) { return (sql_result=mysql_use_result(&sql_handle)); } MYSQL_RES* MYCLASS::StoreResult (void) { return (sql_result=mysql_store_result(&sql_handle)); } MYSQL_ROW MYCLASS::FetchRow (void) { return mysql_fetch_row(sql_result); } void MYCLASS::FreeResult (MYSQL_RES* result) { if (result) { mysql_free_result(result); } else { mysql_free_result(sql_result); } } -------------------------------------------------------- In very short words, after the UseResult()/StoreResult()+FetchRows() when I call FreeResult() it crashes aleatory... MYCLASS members are very simple as you can see, it does not improve nothing new, just encapsulates a standalone connection with isolated pointers, arrays, etc. What may be wrong that when mysql_free_result(sql_result); is called the program crashes? NOTE THAT ALL DATA IS RETRIEVED SUCCESSFULLY AND COMPLETE, THE PROBLEM COMES WHEN I FREE THE RESOURCES... *** glibc detected *** double free or corruption (!prev): 0x08051d58 *** Aborted mysql_free_result(sql_result) is called ONLY ONE TIME, so why the hell the error says double free? that reduces options to corruption but why? I will try to move to an older MySQL (currently have the latest) to see if the error continues, but if it persists, what may produce the error? the way I ./configure'd it maybe? Thanks for your patience... -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]