[MDEV-31578] DECLARE CURSOR: "Memory not freed: 280 bytes lost" on syntax error Created: 2023-06-29  Updated: 2023-07-06  Resolved: 2023-06-29

Status: Closed
Project: MariaDB Server
Component/s: Parser, Stored routines
Affects Version/s: 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0, 11.1, 11.2
Fix Version/s: 10.8.8, 10.4.31, 10.5.22, 10.6.15, 10.9.8, 10.10.6, 10.11.5, 11.0.3, 11.1.2, 11.2.1

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-30680 Warning: Memory not freed: 280 on man... Closed

 Description   

This test script:

DELIMITER $$;
--error ER_PARSE_ERROR
BEGIN NOT ATOMIC
  DECLARE cur CURSOR (a INT) FOR SELECT a+1;
  OPEN cur(sp_followed_by_syntax_error();
  CLOSE cur;
END;
$$
DELIMITER ;$$

makes MTR complain about a memory leak:

Warning: 280 bytes lost at 0x7fe82800aba0, allocated by T@0 at mysys/array.c:72, mysys/hash.c:99, sql/sp.cc:2331, sql/sp.cc:2646, sql/item_create.cc:2631, sql/item_create.cc:2477, sql/sql_yacc.yy:10752, sql/sql_parse.cc:10456
Warning: 280 bytes lost at 0x7fe82800aba0, allocated by T@0 at mysys/array.c:72, mysys/hash.c:99, sql/sp.cc:2331, sql/sp.cc:2646, sql/item_create.cc:2631, sql/item_create.cc:2477, sql/sql_yacc.yy:10752, sql/sql_parse.cc:10456

This is a similar problem to MDEV-30680, but the parse error happens in a different syntax context.

The problem happens in the 10.5 tree with MDEV-30680 already pushed.



 Comments   
Comment by Alice Sherepa [ 2023-06-29 ]

also on 10.4:

MariaDB Version 10.4.31-MariaDB-debug
==============================================================================
 
TEST                                      RESULT   TIME (ms) or COMMENT
--------------------------------------------------------------------------
 
worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 16000..16019
BEGIN NOT ATOMIC
DECLARE cur CURSOR (a INT) FOR SELECT a+1;
OPEN cur(sp_followed_by_syntax_error();
CLOSE cur;
END;
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ';
CLOSE cur;
END' at line 3
main.1_my                                [ pass ]      1
***Warnings generated in error logs during shutdown after running tests: main.1_my
 
Warning: Memory not freed: 256
Warning:  256 bytes lost at 0x61300006b8f0, allocated by T@0 at mysys/my_malloc.c:101, mysys/array.c:70, mysys/hash.c:98, sql/sp.cc:2291, sql/sp.cc:2606, sql/item_create.cc:3615, sql/item_create.cc:3461, sql/sql_yacc.yy:11513
Warning:  256 bytes lost at 0x61300006b8f0, allocated by T@0 at mysys/my_malloc.c:101, mysys/array.c:70, mysys/hash.c:98, sql/sp.cc:2291, sql/sp.cc:2606, sql/item_create.cc:3615, sql/item_create.cc:3461, sql/sql_yacc.yy:11513

Generated at Thu Feb 08 10:24:55 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.