[MDEV-26986] LeakSanitizer/Valgrind errors in Binary_string::real_alloc upon INSERT DELAYED with unique blob and binary log Created: 2021-11-06  Updated: 2023-09-27  Resolved: 2023-09-27

Status: Closed
Project: MariaDB Server
Component/s: Data Manipulation - Insert, Replication, Virtual Columns
Affects Version/s: 10.4, 10.5, 10.6, 10.7
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Oleksandr Byelkin
Resolution: Duplicate Votes: 0
Labels: None

Issue Links:
Duplicate
is duplicated by MDEV-28013 Memory leak on INSERT DELAYED Closed
Relates
relates to MDEV-19848 Server crashes in check_vcol_forward_... Closed
relates to MDEV-22525 Backport MDEV-19848 (Server crashes i... Closed
relates to MDEV-24467 Memory not freed after failed INSERT ... Closed

 Description   

Note: I assume 10.4 is also affected, but currently the test case crashes on 10.4 with MDEV-22525 instead (in 10.5+ it was fixed within MDEV-19848).
Note: The patch for MDEV-24467 is already in the branch.

--source include/have_log_bin.inc
 
CREATE TABLE t (a TIMESTAMP, b TEXT, UNIQUE(a,b)) ENGINE=MyISAM;
INSERT DELAYED INTO t VALUES ('2012-12-12','foo');
 
# Cleanup
DROP TABLE t;

bb-10.5-release 8635be6a296 with ASAN

Warning: Memory not freed: 48
 
=================================================================
==1340083==ERROR: LeakSanitizer: detected memory leaks
 
Direct leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7fee5ce17bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
    #1 0x55bac2ed503c in my_malloc /data/src/bb-10.5-release/mysys/my_malloc.c:90
    #2 0x55bac140a593 in Binary_string::real_alloc(unsigned long) /data/src/bb-10.5-release/sql/sql_string.cc:44
    #3 0x55bac0ed6007 in Binary_string::alloc(unsigned long) /data/src/bb-10.5-release/sql/sql_string.h:639
    #4 0x55bac19413f8 in Field_timestamp::val_str(String*, String*) /data/src/bb-10.5-release/sql/field.cc:5377
    #5 0x55bac1a25fff in Item_field::val_str(String*) /data/src/bb-10.5-release/sql/item.cc:3304
    #6 0x55bac13415e2 in Item::val_str() /data/src/bb-10.5-release/sql/item.h:915
    #7 0x55bac1b1c1ad in Item_func_hash::val_int() /data/src/bb-10.5-release/sql/item_func.cc:1784
    #8 0x55bac1a42542 in Item::save_int_in_field(Field*, bool) /data/src/bb-10.5-release/sql/item.cc:6791
    #9 0x55bac176774d in Type_handler_int_result::Item_save_in_field(Item*, Field*, bool) const /data/src/bb-10.5-release/sql/sql_type.cc:4349
    #10 0x55bac1a42728 in Item::save_in_field(Field*, bool) /data/src/bb-10.5-release/sql/item.cc:6801
    #11 0x55bac1526999 in TABLE::update_virtual_fields(handler*, enum_vcol_update_mode) /data/src/bb-10.5-release/sql/table.cc:8666
    #12 0x55bac102fb34 in fill_record(THD*, TABLE*, Field**, List<Item>&, bool, bool) /data/src/bb-10.5-release/sql/sql_base.cc:8807
    #13 0x55bac102fe42 in fill_record_n_invoke_before_triggers(THD*, TABLE*, Field**, List<Item>&, bool, trg_event_type) /data/src/bb-10.5-release/sql/sql_base.cc:8849
    #14 0x55bac10e63e5 in mysql_insert(THD*, TABLE_LIST*, List<Item>&, List<List<Item> >&, List<Item>&, List<Item>&, enum_duplicates, bool, select_result*) /data/src/bb-10.5-release/sql/sql_insert.cc:1061
    #15 0x55bac11b03bd in mysql_execute_command(THD*) /data/src/bb-10.5-release/sql/sql_parse.cc:4624
    #16 0x55bac11c88ed in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/bb-10.5-release/sql/sql_parse.cc:8100
    #17 0x55bac119e7ae in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/bb-10.5-release/sql/sql_parse.cc:1891
    #18 0x55bac119b0ed in do_command(THD*) /data/src/bb-10.5-release/sql/sql_parse.cc:1370
    #19 0x55bac15e5b5c in do_handle_one_connection(CONNECT*, bool) /data/src/bb-10.5-release/sql/sql_connect.cc:1418
    #20 0x55bac15e5375 in handle_one_connection /data/src/bb-10.5-release/sql/sql_connect.cc:1312
    #21 0x55bac2250aa4 in pfs_spawn_thread /data/src/bb-10.5-release/storage/perfschema/pfs.cc:2201
    #22 0x7fee5c74e608 in start_thread /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477
 
SUMMARY: AddressSanitizer: 48 byte(s) leaked in 1 allocation(s).

10.5 a8ded395 with Valgrind

Warning: Memory not freed: 48
==1340353== 48 bytes in 1 blocks are definitely lost in loss record 1 of 2
==1340353==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==1340353==    by 0x173007D: my_malloc (my_malloc.c:90)
==1340353==    by 0xB21590: Binary_string::real_alloc(unsigned long) (sql_string.cc:44)
==1340353==    by 0x8FB254: Binary_string::alloc(unsigned long) (sql_string.h:639)
==1340353==    by 0xD84282: Field_timestamp::val_str(String*, String*) (field.cc:5377)
==1340353==    by 0xDE11DB: Item_field::val_str(String*) (item.cc:3304)
==1340353==    by 0xAD712F: Item::val_str() (item.h:915)
==1340353==    by 0xE4A61A: Item_func_hash::val_int() (item_func.cc:1784)
==1340353==    by 0xDEC195: Item::save_int_in_field(Field*, bool) (item.cc:6791)
==1340353==    by 0xC9342F: Type_handler_int_result::Item_save_in_field(Item*, Field*, bool) const (sql_type.cc:4349)
==1340353==    by 0xDEC24E: Item::save_in_field(Field*, bool) (item.cc:6801)
==1340353==    by 0xB933A2: TABLE::update_virtual_fields(handler*, enum_vcol_update_mode) (table.cc:8666)
==1340353==    by 0x996B39: fill_record(THD*, TABLE*, Field**, List<Item>&, bool, bool) (sql_base.cc:8807)
==1340353==    by 0x996C42: fill_record_n_invoke_before_triggers(THD*, TABLE*, Field**, List<Item>&, bool, trg_event_type) (sql_base.cc:8849)
==1340353==    by 0x9E40B9: mysql_insert(THD*, TABLE_LIST*, List<Item>&, List<List<Item> >&, List<Item>&, List<Item>&, enum_duplicates, bool, select_result*) (sql_insert.cc:1061)
==1340353==    by 0xA39298: mysql_execute_command(THD*) (sql_parse.cc:4624)



 Comments   
Comment by Nayuta Yanagisawa (Inactive) [ 2022-03-07 ]

The test case below results in a memory leak. At least confirmed on 10.5 (e8e755ea6cbac56d561375b940281a903c7db61c) debug build.
This looks quite similar to the present issue.

CREATE TABLE tbl_a (a INT UNSIGNED KEY,b INT UNSIGNED,c INT UNSIGNED,UNIQUE (b, c) USING HASH) ENGINE=MyISAM;
SHOW CREATE TABLE tbl_a;
INSERT DELAYED INTO tbl_a VALUES (0,0,0);

e8e755ea6cbac56d561375b940281a903c7db61c (debug)

Warning: Memory not freed: 80
Warning:   40 bytes lost at 0x7f65ec196a80, allocated by T@0 at 0x559424d00aa1, sql/sql_string.cc:44, sql/sql_string.h:639, sql/field.cc:4254, sql/field.cc:4435, sql/item.cc:3288, sql/item.h:915, sql/item_func.cc:1776
Warning:   40 bytes lost at 0x7f65ec0c3ea0, allocated by T@0 at sql/item.cc:6757, sql/sql_string.h:639, sql/field.cc:4254, sql/field.cc:4435, sql/item.cc:3288, sql/item.h:915, sql/item_func.cc:1776, sql/item.cc:6757
Warning:   40 bytes lost at 0x7f65ec196a80, allocated by T@0 at sql/sql_string.cc:44, sql/sql_string.h:639, sql/field.cc:4254, sql/field.cc:4435, sql/item.cc:3288, sql/item.h:915, sql/item_func.cc:1776, sql/item.cc:6757
Warning:   40 bytes lost at 0x7f65ec0c3ea0, allocated by T@0 at sql/sql_string.cc:44, sql/sql_string.h:639, sql/field.cc:4254, sql/field.cc:4435, sql/item.cc:3288, sql/item.h:915, sql/item_func.cc:1776, sql/item.cc:6757

Generated at Thu Feb 08 09:49:28 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.