Explorar o código

db_mysql: fixes FS#434, Kamailio will eat sometimes 100% CPU due a bug in db_mysql

* Fixes FS#434 reported from Maxim, incorrect mysql API usage for mysql_next_result(..)
* According MySQL doc, return values for mysql_next_result(..) can be the following:
  0 - Successful and there are more results
  -1 - Successful and there are no more results
  >0 - An error occured
* Thus, if there will be an error when reading a next result, the code will be infinitely
  looped in “while” cycle and current process will eat 100% CPU (The mysql_more_results
  will not help here because it just checks a local flag that will be set to TRUE in cases
  when there will be more than one result).
* The solution is to replace " > 0” with " == 0”:
Henning Westerholt %!s(int64=11) %!d(string=hai) anos
pai
achega
0d7d5dc4d7
Modificáronse 1 ficheiros con 2 adicións e 2 borrados
  1. 2 2
      modules/db_mysql/km_dbase.c

+ 2 - 2
modules/db_mysql/km_dbase.c

@@ -258,7 +258,7 @@ static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r)
 		db_mysql_free_result(_h, *_r);
 		*_r = 0;
 #if (MYSQL_VERSION_ID >= 40100)
-		while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) > 0 ) {
+		while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) == 0 ) {
 			MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) );
 			mysql_free_result(res);
 		}
@@ -268,7 +268,7 @@ static int db_mysql_store_result(const db1_con_t* _h, db1_res_t** _r)
 
 done:
 #if (MYSQL_VERSION_ID >= 40100)
-	while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) > 0 ) {
+	while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) == 0 ) {
 		MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) );
 		mysql_free_result(res);
 	}