Bug #5287 Stored procedure crash if leave outside loop
Submitted: 30 Aug 2004 3:53 Modified: 2 Sep 2004 17:26
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.2-alpha-debug OS:Linux (SuSE 8.2)
Assigned to: Per-Erik Martin CPU Architecture:Any

[30 Aug 2004 3:53] Peter Gulutzan
Description:
LEAVE label_name should mean "exit the labelled statement that is identified by 
label_name". Generally this statement is for exiting a flow control statement (e.g. a loop) 
but labels can also precede BEGIN. If it's LEAVE X and X is a label for a BEGIN which 
starts with a cursor declaration, I get a crash. 
 
 

How to repeat:
mysql> delimiter // 
mysql> create procedure p24 (param1 int) label1: begin declare c cursor for select 5; loop 
if param1 >= 0 then leave label1; end if; end loop; end;// 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> set @a = 0// 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> call p24(@a)// 
ERROR 2013 (HY000): Lost connection to MySQL server during query
[30 Aug 2004 16:40] MySQL Verification Team
(gdb) bt
#0  0x08255143 in sp_rcontext::pop_cursors (this=0x86abc00, count=2) at sp_rcontext.cc:127
#1  0x08253327 in sp_instr_cpop::execute (this=0x86a7ee8, thd=0x8691138, nextp=0xbf5ff1c0) at sp_head.cc:1557
#2  0x08250151 in sp_head::execute (this=0x86a79d0, thd=0x8691138) at sp_head.cc:464
#3  0x082508c9 in sp_head::execute_procedure (this=0x86a79d0, thd=0x8691138, args=0x8691564) at sp_head.cc:677
#4  0x0816f740 in mysql_execute_command (thd=0x8691138) at sql_parse.cc:3667
#5  0x08171009 in mysql_parse (thd=0x8691138, inBuf=0x86ab9f8 "call p24(@a)", length=12) at sql_parse.cc:4432
#6  0x0816a492 in dispatch_command (command=COM_QUERY, thd=0x8691138, packet=0x86a3999 "call p24(@a)",
    packet_length=13) at sql_parse.cc:1514
#7  0x08169d9c in do_command (thd=0x8691138) at sql_parse.cc:1296
#8  0x0816930c in handle_one_connection (arg=0x8691138) at sql_parse.cc:1032
#9  0x4016314b in pthread_start_thread () from /lib/libpthread.so.0
#10 0x401631df in pthread_start_thread_event () from /lib/libpthread.so.0
#11 0x402df50a in clone () from /lib/libc.so.6
[2 Sep 2004 17:26] Per-Erik Martin
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html