Re: Memory leaks using MySQL C Api
try this, i found this when solving similar problem.There is another method to make and free connection, here is just one change. The trick is that you dont call mysql_close( ) on mysql_connection , but on return of mysql_real_connect(); Try it, i think that this solve your is problem. static MYSQL myMYSQL ; static MYSQL *myData ; mysql_init(myMYSQL); if ( myData=mysql_real_connect( myMYSQL, localhost, puberusr, puber1234, pubernew, MYSQL_PORT, NULL, 0 ) ) { if ( mysql_select_db( myData, pubernew ) 0 ) { DisplayException(mysql_error(myMYSQL)); mysql_close( myData ) ; } } else { DisplayException(mysql_error(myMYSQL)); mysql_close( myData ) ; } - Original Message - From: John McCaskey [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Sunday, January 18, 2004 8:31 AM Subject: Re: Memory leaks using MySQL C Api Agreed, I am not calling mysql_store_result(). I attempted to add my_free() but the function does not seem to exist, it is also not listed in the API docs for the c api. As such it still seems that there should be no leak, but yet I do get one. Thanks for the idea anyway Chris, maybe you can clarify for us once more. John McCaskey On Sat, 2004-01-17 at 12:44, Aftab Jahan Subedar wrote: Hey wait a minute. Where did you get the my_free(), may be you are trying to say mysql_free(), but then that is used only if result set is used/called. But the code does not show any result set call. ie. mysql_use_result() or mysql_store_result(). So, the question now, how come there is a leak here. I dont see any, does anyone see any? Chris Nolan wrote: Hi! You're looking for the function my_free(). Enjoy! Regards, Chris John McCaskey wrote: I have the following code: //try the mysql connection mysql_init(mysql_connection); if(!mysql_real_connect(mysql_connection, db_host, db_user, db_pass, db_db, 0, NULL, 0)) { flockfile(stderr); fprintf(stderr, %s: Failed to connect to database: Error: %s\n, timestamp, mysql_error(mysql_connection)); funlockfile(stderr); mysql_close(mysql_connection); return(2); } mysql_close(mysql_connection); This code is creating a memory leak. Am I missing some cleanup calls? I'm under the impression all I should need to do is call mysql_close to clean up the connection? I'm testing this using mtrace, if I place a return directly above the code segment it reports no leaks, if I place it direcly below the fragment there are several variables reported as not being freed. Any ideas? John A. McCaskey -- Aftab Jahan Subedar CEO/Software Engineer Subedar Technologies Subedar Baag Bibir Bagicha #1 North Jatrabari Dhaka 1204 Bangladesh http://www.SubedarTechnologies.com http://www.DhakaStockExchangeGame.com/ http://www.CEOBangladesh.com/ http://www.NYSEGame.com tel://+88027519050 EMail://[EMAIL PROTECTED] - Directly to my notebook -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: Memory leaks using MySQL C Api
Agreed, I am not calling mysql_store_result(). I attempted to add my_free() but the function does not seem to exist, it is also not listed in the API docs for the c api. As such it still seems that there should be no leak, but yet I do get one. Thanks for the idea anyway Chris, maybe you can clarify for us once more. John McCaskey On Sat, 2004-01-17 at 12:44, Aftab Jahan Subedar wrote: Hey wait a minute. Where did you get the my_free(), may be you are trying to say mysql_free(), but then that is used only if result set is used/called. But the code does not show any result set call. ie. mysql_use_result() or mysql_store_result(). So, the question now, how come there is a leak here. I dont see any, does anyone see any? Chris Nolan wrote: Hi! You're looking for the function my_free(). Enjoy! Regards, Chris John McCaskey wrote: I have the following code: //try the mysql connection mysql_init(mysql_connection); if(!mysql_real_connect(mysql_connection, db_host, db_user, db_pass, db_db, 0, NULL, 0)) { flockfile(stderr); fprintf(stderr, %s: Failed to connect to database: Error: %s\n, timestamp, mysql_error(mysql_connection)); funlockfile(stderr); mysql_close(mysql_connection); return(2); } mysql_close(mysql_connection); This code is creating a memory leak. Am I missing some cleanup calls? I'm under the impression all I should need to do is call mysql_close to clean up the connection? I'm testing this using mtrace, if I place a return directly above the code segment it reports no leaks, if I place it direcly below the fragment there are several variables reported as not being freed. Any ideas? John A. McCaskey -- Aftab Jahan Subedar CEO/Software Engineer Subedar Technologies Subedar Baag Bibir Bagicha #1 North Jatrabari Dhaka 1204 Bangladesh http://www.SubedarTechnologies.com http://www.DhakaStockExchangeGame.com/ http://www.CEOBangladesh.com/ http://www.NYSEGame.com tel://+88027519050 EMail://[EMAIL PROTECTED] - Directly to my notebook -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: Memory leaks using MySQL C Api
Hi! You're looking for the function my_free(). Enjoy! Regards, Chris John McCaskey wrote: I have the following code: //try the mysql connection mysql_init(mysql_connection); if(!mysql_real_connect(mysql_connection, db_host, db_user, db_pass, db_db, 0, NULL, 0)) { flockfile(stderr); fprintf(stderr, %s: Failed to connect to database: Error: %s\n, timestamp, mysql_error(mysql_connection)); funlockfile(stderr); mysql_close(mysql_connection); return(2); } mysql_close(mysql_connection); This code is creating a memory leak. Am I missing some cleanup calls? I'm under the impression all I should need to do is call mysql_close to clean up the connection? I'm testing this using mtrace, if I place a return directly above the code segment it reports no leaks, if I place it direcly below the fragment there are several variables reported as not being freed. Any ideas? John A. McCaskey -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: Memory leaks using MySQL C Api
Hey wait a minute. Where did you get the my_free(), may be you are trying to say mysql_free(), but then that is used only if result set is used/called. But the code does not show any result set call. ie. mysql_use_result() or mysql_store_result(). So, the question now, how come there is a leak here. I dont see any, does anyone see any? Chris Nolan wrote: Hi! You're looking for the function my_free(). Enjoy! Regards, Chris John McCaskey wrote: I have the following code: //try the mysql connection mysql_init(mysql_connection); if(!mysql_real_connect(mysql_connection, db_host, db_user, db_pass, db_db, 0, NULL, 0)) { flockfile(stderr); fprintf(stderr, %s: Failed to connect to database: Error: %s\n, timestamp, mysql_error(mysql_connection)); funlockfile(stderr); mysql_close(mysql_connection); return(2); } mysql_close(mysql_connection); This code is creating a memory leak. Am I missing some cleanup calls? I'm under the impression all I should need to do is call mysql_close to clean up the connection? I'm testing this using mtrace, if I place a return directly above the code segment it reports no leaks, if I place it direcly below the fragment there are several variables reported as not being freed. Any ideas? John A. McCaskey -- Aftab Jahan Subedar CEO/Software Engineer Subedar Technologies Subedar Baag Bibir Bagicha #1 North Jatrabari Dhaka 1204 Bangladesh http://www.SubedarTechnologies.com http://www.DhakaStockExchangeGame.com/ http://www.CEOBangladesh.com/ http://www.NYSEGame.com tel://+88027519050 EMail://[EMAIL PROTECTED] - Directly to my notebook -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Memory leaks using MySQL C Api
I have the following code: //try the mysql connection mysql_init(mysql_connection); if(!mysql_real_connect(mysql_connection, db_host, db_user, db_pass, db_db, 0, NULL, 0)) { flockfile(stderr); fprintf(stderr, %s: Failed to connect to database: Error: %s\n, timestamp, mysql_error(mysql_connection)); funlockfile(stderr); mysql_close(mysql_connection); return(2); } mysql_close(mysql_connection); This code is creating a memory leak. Am I missing some cleanup calls? I'm under the impression all I should need to do is call mysql_close to clean up the connection? I'm testing this using mtrace, if I place a return directly above the code segment it reports no leaks, if I place it direcly below the fragment there are several variables reported as not being freed. Any ideas? John A. McCaskey