Module: sip-router
Branch: master
Commit: 0d7d5dc4d7219c5beb9a150cc56e74edac9dc4d5
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0d7d5dc4d7219c5beb9a150cc56e74edac9dc4d5

Author: Henning Westerholt <[email protected]>
Committer: Henning Westerholt <[email protected]>
Date:   Tue May 27 12:14:24 2014 +0200

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”:

---

 modules/db_mysql/km_dbase.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/modules/db_mysql/km_dbase.c b/modules/db_mysql/km_dbase.c
index cf22e4c..d2ef5c5 100644
--- a/modules/db_mysql/km_dbase.c
+++ b/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);
        }


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to