Bug #93164 Memory leak in innochecksum utility detected by ASan
Submitted: 12 Nov 2018 14:21 Modified: 4 Dec 2018 17:44
Reporter: Yura Sorokin (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.7.23, 5.7.24 OS:Any
Assigned to: CPU Architecture:Any

[12 Nov 2018 14:21] Yura Sorokin
Description:
The following memory leak is detected by ASan in the innochecksum utility

==55500==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 131072 byte(s) in 1 object(s) allocated from:
    #0 0x7fe4c14b2b50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
    #1 0x560f2cdd5bf3 in main /mnt/hgfs/repos/mysql-server/extra/innochecksum.cc:1173
    #2 0x7fe4c03ccb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

SUMMARY: AddressSanitizer: 131072 byte(s) leaked in 1 allocation(s).

How to repeat:
Build MySQL Server with Address Sanitizer enabled on Ubuntu 18.04 with default GCC (7.3.0)

cmake ... -DWITH_ASAN=ON -DWITH_ASAN_SCOPE=ON

Run
./mtr --debug-server innodb.innodb-wl6045-linux

Output
mysqltest: At line 394: command "$INNOCHECKSUM $MYSQLD_DATADIR/test/t1.ibd 2> $SEARCH_FILE" failed with wrong error: 42

Content of the 'log/my_restart.err' file

Error: Unable to lock file:: /home/yura/addon/mysql-build-5.7-asan_scope/mysql-test/var/mysqld.1/data//test/t1.ibd
fcntl: Resource temporarily unavailable

=================================================================
==55500==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 131072 byte(s) in 1 object(s) allocated from:
    #0 0x7fe4c14b2b50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
    #1 0x560f2cdd5bf3 in main /mnt/hgfs/repos/mysql-server/extra/innochecksum.cc:1173
    #2 0x7fe4c03ccb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

SUMMARY: AddressSanitizer: 131072 byte(s) leaked in 1 allocation(s).

Suggested fix:
Free buffer allocated in the 'extra/innochecksum.cc' on error return paths as well.
[12 Nov 2018 14:38] Yura Sorokin
8.0 most probably is also affected.
[12 Nov 2018 14:46] Yura Sorokin
Suggested patch for 5.7

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: bugps93164_5.7.diff (application/octet-stream, text), 1.01 KiB.

[13 Nov 2018 9:11] MySQL Verification Team
Hello Yura,

Thank you for the report and contribution.
I'm seeing this issue on 5.7.23 but no longer with 5.7.24. Could you please confirm if you are seeing this on 5.7.24? In that case may I request to please provide exact cmake options used for the build? I'm joining build and test results from my environment shortly for your reference.

regards,
Umesh
[13 Nov 2018 9:11] MySQL Verification Team
test results

Attachment: 93164_93165.results (application/octet-stream, text), 10.71 KiB.

[13 Nov 2018 14:17] Yura Sorokin
Umesh,

It looks like all these memory problems were brutally suppressed in 5.7.24
https://github.com/mysql/mysql-server/commit/e93e8db42d89154b37f63772ce68c1efda637609

Error code 42 is returned when ASan detects memory leaks in auxiliary utilities (like innochecksum) and adding
'42' to the list of expected '--error' codes is not a proper way to fix the problem.

This particular issue is 100% legitimate memory leak and should be fixed properly.
[13 Nov 2018 14:54] MySQL Verification Team
Thank you for the feedback.

regards,
Umesh
[4 Dec 2018 17:44] Daniel Price
Posted by developer:
 
Fixed as of the upcoming 5.7.26, 8.0.15 release, and here's the changelog entry:

Memory leaks discovered in the innochecksum utility were removed.