Bug #93925 | Possible memory leak in libmysqlclient20 | ||
---|---|---|---|
Submitted: | 15 Jan 2019 0:18 | Modified: | 22 Jan 2019 11:34 |
Reporter: | Arjuna Del Toso | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: C API (client library) | Severity: | S3 (Non-critical) |
Version: | 5.7.24 | OS: | Linux |
Assigned to: | MySQL Verification Team | CPU Architecture: | Any |
[15 Jan 2019 0:18]
Arjuna Del Toso
[15 Jan 2019 0:19]
Arjuna Del Toso
The code exposing the issue
Attachment: mysql-bug.c (text/x-csrc), 2.75 KiB.
[22 Jan 2019 11:34]
MySQL Verification Team
Hi, Thanks for report, but this is not a bug yes, when I run your code: [arhimed@localhost ~]$ gcc -g -O0 bug93925.c -o mysql-bug -I/home/arhimed/mysql/5.7.24/include/mysql/ -I/home/arhimed/mysql/5.7.24/include/ -L/home/arhimed/mysql/5.7.24/lib/ -lmysqlclient [arhimed@localhost ~]$ LD_LIBRARY_PATH=/home/arhimed/mysql/5.7.24/lib ./mysql-bug 2 row: a row: b [arhimed@localhost ~]$ LD_LIBRARY_PATH=/home/arhimed/mysql/5.7.24/lib valgrind --leak-check=yes ./mysql-bug 2 ==67433== Memcheck, a memory error detector ==67433== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==67433== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info ==67433== Command: ./mysql-bug 2 ==67433== row: a row: b ==67433== ==67433== HEAP SUMMARY: ==67433== in use at exit: 79,976 bytes in 5 blocks ==67433== total heap usage: 86 allocs, 81 frees, 173,176 bytes allocated ==67433== ==67433== 7,272 (912 direct, 6,360 indirect) bytes in 1 blocks are definitely lost in loss record 4 of 5 ==67433== at 0x4C2A988: calloc (vg_replace_malloc.c:711) ==67433== by 0x4E94D06: my_raw_malloc (my_malloc.c:189) ==67433== by 0x4E94D06: my_malloc (my_malloc.c:54) ==67433== by 0x4E5F22A: mysql_stmt_init (libmysql.c:1552) ==67433== by 0x400DF7: main (bug93925.c:46) ==67433== ==67433== LEAK SUMMARY: ==67433== definitely lost: 912 bytes in 1 blocks ==67433== indirectly lost: 6,360 bytes in 3 blocks ==67433== possibly lost: 0 bytes in 0 blocks ==67433== still reachable: 0 bytes in 0 blocks ==67433== suppressed: 72,704 bytes in 1 blocks ==67433== ==67433== For counts of detected and suppressed errors, rerun with: -v ==67433== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) [arhimed@localhost ~]$
[22 Jan 2019 11:38]
MySQL Verification Team
but when I "fix" your code: [arhimed@localhost ~]$ diff bug93925-original.c bug93925-fixed.c 112c112,113 < if (mysql_stmt_free_result(stmt) != 0) fwprintf(stderr, L"unable to free stmt"); --- > if (mysql_stmt_free_result(stmt) != 0) fwprintf(stderr, L"unable to free result"); > if (mysql_stmt_close(stmt) != 0) fwprintf(stderr, L"unable to free stmt"); as you forgot to free the statement, your error for freeing result mentions statement but actually you have to free result (you are doing it properly but with wrong error msg) and then you need to (and you forgot) free the actual statement with https://dev.mysql.com/doc/refman/5.7/en/mysql-stmt-close.html you get: [arhimed@localhost ~]$ LD_LIBRARY_PATH=/home/arhimed/mysql/5.7.24/lib valgrind --leak-check=yes ./mysql-bug 2 ==67460== Memcheck, a memory error detector ==67460== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==67460== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info ==67460== Command: ./mysql-bug 2 ==67460== row: a row: b ==67460== ==67460== HEAP SUMMARY: ==67460== in use at exit: 72,704 bytes in 1 blocks ==67460== total heap usage: 86 allocs, 85 frees, 173,176 bytes allocated ==67460== ==67460== LEAK SUMMARY: ==67460== definitely lost: 0 bytes in 0 blocks ==67460== indirectly lost: 0 bytes in 0 blocks ==67460== possibly lost: 0 bytes in 0 blocks ==67460== still reachable: 0 bytes in 0 blocks ==67460== suppressed: 72,704 bytes in 1 blocks ==67460== ==67460== For counts of detected and suppressed errors, rerun with: -v ==67460== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) all best Bogdan