Bug #73 mysql_stmt_close after mysql_close
Submitted: 14 Feb 2003 4:02 Modified: 22 Feb 2003 7:21
Reporter: Georg Richter Email Updates:
Status: Closed Impact on me:
Category:MySQL Server Severity:S3 (Non-critical)
Version: OS:
Assigned to: Bugs System CPU Architecture:Any

[14 Feb 2003 4:02] Georg Richter
When I call mysql_stmt_close after mysql_close mysql_stmt_close segfaults in net_safe_read (cause the connection is already closed, and stmt->mysql has an undefined status).

How to repeat:

Suggested fix:
Check if stmt->mysql is still valid, and if not only free stmt and his sub structs.
[14 Feb 2003 12:17] Venu Anuganti
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem is not the result of a bug.
For a list of more appropriate places to ask for help using MySQL
products, please visit http://www.mysql.com/support/

Thank you for your interest in MySQL.

Hi !! 
This is expected, and we don't like to check for the 
negative cases like this as this makes the interface to 
have extra checks. 
Once you close the connection, all its related information 
(open statements) are freed automatically including from 
server to avoid memory leaks, and you can't use the the 
same statements in subsequent calls. 
This is similar to calling a mysql_real_query() after 
mysql_close() is called, and expecting a error code. 
So, the above segfault is expected, and you may still get 
weired things as the stmt is not valid after the connection 
associated with it is closed. 
I will add this information in the prepare.texi document. 
Thanks for the report.
[14 Feb 2003 13:50] Georg Richter
Hi Venu,

Quickfix should be expected behaviour :)

After calling mysql_close the stmt, which was allocated via mysql_prepare isn't freed on client side. So I have to free it and also some other pointers like bind manually in the application, which isn't a good idea.
[15 Feb 2003 15:48] Venu Anuganti

When you call mysql_close(), and if that connection handle has 'n' statements open, all these are freed from client(all bind resources associcated with stmts, see stmt_close() from libmysql.c) end as well as from server end.

You can cross check this behaviour from test 'test_stmt_close()' from client_test.c; which actually covers this scenario.

Regarding the application end, I am not sure how does that relates to this, becuase its up to application to decide when to call mysql_close().

Or did I missed something ? 

[22 Feb 2003 7:21] Georg Richter
changed status