Bug #89384 Memory leak in 'pfs-t' unit test ('test_locker_disabled()')
Submitted: 24 Jan 2018 14:54 Modified: 1 Jun 2018 18:36
Reporter: Yura Sorokin (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Tests: Server Severity:S3 (Non-critical)
Version:5.6.39 OS:Any
Assigned to: CPU Architecture:Any

[24 Jan 2018 14:54] Yura Sorokin
Description:
'pfs-t' unit test from MySQL Server built in release mode (-DCMAKE_BUILD_TYPE=RelWithDebInfo) with address sanitizer enabled (-DWITH_ASAN) generates the following output:

==89756==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7f352700fd38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
    #1 0x55c8b52aef09 in my_malloc /home/yura/ws/mysql-server/mysys/my_malloc.c:38
    #2 0x55c8b52b68ed in _lf_alloc_new /home/yura/ws/mysql-server/mysys/lf_alloc-pin.c:440
    #3 0x55c8b52b90c5 in lf_hash_insert /home/yura/ws/mysql-server/mysys/lf_hash.c:373
    #4 0x55c8b527e95c in find_or_create_file(PFS_thread*, PFS_file_class*, char const*, unsigned int, bool) /home/yura/ws/mysql-server/storage/perfschema/pfs_instr.cc:1352
    #5 0x55c8b52a260d in create_file_v1 /home/yura/ws/mysql-server/storage/perfschema/pfs.cc:1792
    #6 0x55c8b526cdff in test_init_disabled() /home/yura/ws/mysql-server/storage/perfschema/unittest/pfs-t.cc:899
    #7 0x55c8b5273052 in do_all_tests() /home/yura/ws/mysql-server/storage/perfschema/unittest/pfs-t.cc:1658
    #8 0x55c8b5265f08 in main /home/yura/ws/mysql-server/storage/perfschema/unittest/pfs-t.cc:1668
    #9 0x7f35269531c0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x211c0)

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

How to repeat:
GCC 5.X/6.X/7.X required

cmake \
 . \
 -DCMAKE_BUILD_TYPE=RelWithDebInfo \
 -DBUILD_CONFIG=mysql_release \
 -DFEATURE_SET=community \
 -DWITH_SSL=system \
 -DENABLE_DOWNLOADS=1 \
 -DWITH_EMBEDDED_SERVER=OFF \
 -DWITH_ASAN=ON
make -j8
./storage/perfschema/unittest/pfs-t

Suggested fix:
Explicitly call 'destroy_file()' after successful 'psi->create_file()' in 'test_init_disabled()'

See the attached patch.
[24 Jan 2018 14:56] Yura Sorokin
Suggested patch

Attachment: bug89384.diff (application/octet-stream, text), 971 bytes.

[25 Jan 2018 5:35] MySQL Verification Team
Hello Yura,

Thank you for the report and feedback.
Verified as described.

Thanks,
Umesh
[25 Jan 2018 5:36] MySQL Verification Team
5.6.39 - test results

Attachment: 89384_5.6.39.results (application/octet-stream, text), 115.31 KiB.

[25 Jan 2018 5:40] MySQL Verification Team
Please ensure to re-send the patch via "Contributions" tab. Otherwise we would not be able to accept it.

Thanks,
Umesh
[25 Jan 2018 6:21] MySQL Verification Team
-- 5.7.21 - no issues observed
With exact steps(included BOOST for 5.7) and on same instance

[umshastr@vilma40]~/bugs/mysql-5.7.21: ./storage/perfschema/unittest/pfs-t
1..232
# test_bootstrap
ok 1 - boot
ok 2 - boot->get_interface
ok 3 - no version 0
ok 4 - version 1
ok 5 - version 2
# test_bad_registration
ok 6 - zero key
ok 7 - zero key
ok 8 - zero key
ok 9 - zero key
ok 10 - zero key
ok 11 - assigned key
ok 12 - zero key
ok 13 - zero key
ok 14 - assigned key
ok 15 - zero key
ok 16 - zero key
ok 17 - zero key
ok 18 - zero key
ok 19 - zero key
ok 20 - assigned key
ok 21 - zero key
ok 22 - zero key SX
ok 23 - zero key
ok 24 - assigned key
ok 25 - zero key SX
ok 26 - assigned key SX
ok 27 - zero key
ok 28 - zero key
ok 29 - zero key
ok 30 - zero key
ok 31 - zero key
ok 32 - assigned key
ok 33 - zero key
ok 34 - zero key
ok 35 - assigned key
ok 36 - zero key
ok 37 - zero key
ok 38 - zero key
ok 39 - zero key
ok 40 - zero key
ok 41 - assigned key
ok 42 - zero key
ok 43 - zero key
ok 44 - assigned key
ok 45 - zero key
ok 46 - zero key
ok 47 - zero key
ok 48 - zero key
ok 49 - zero key
ok 50 - assigned key
ok 51 - zero key
ok 52 - zero key
ok 53 - assigned key
ok 54 - zero key
ok 55 - zero key
ok 56 - zero key
ok 57 - zero key
ok 58 - zero key
ok 59 - assigned key
ok 60 - zero key
ok 61 - zero key
ok 62 - assigned key
# test_init_disabled
ok 63 - T-1
ok 64 - mutex class A
ok 65 - rwlock class A
ok 66 - cond class A
ok 67 - file class A
ok 68 - socket class A
ok 69 - mutex_A1 disabled, instrumented
ok 70 - mutex_A1 enabled, instrumented
ok 71 - mutex key 0 not instrumented
ok 72 - broken mutex key not instrumented
ok 73 - rwlock_A1 disabled, instrumented
ok 74 - rwlock_A1 enabled, instrumented
ok 75 - rwlock key 0 not instrumented
ok 76 - broken rwlock key not instrumented
ok 77 - cond_A1 disabled, instrumented
ok 78 - cond_A1 enabled, instrumented
ok 79 - cond key 0 not instrumented
ok 80 - broken cond key not instrumented
ok 81 - not instrumented
ok 82 - not instrumented
ok 83 - file_A1 not instrumented
ok 84 - file_A1 not instrumented
ok 85 - socket_A1 disabled, instrumented
ok 86 - socket_A1 enabled, instrumented
ok 87 - socket key 0 not instrumented
ok 88 - broken socket key not instrumented
ok 89 - mutex_A1 disabled, instrumented
ok 90 - mutex_A1 enabled, instrumented
ok 91 - mutex_A1 not instrumented
ok 92 - mutex_A1 not instrumented
ok 93 - rwlock_A1 disabled, instrumented
ok 94 - rwlock_A1 enabled, instrumented
ok 95 - rwlock_A1 not instrumented
ok 96 - rwlock_A1 not instrumented
ok 97 - cond_A1 disabled, instrumented
ok 98 - cond_A1 enabled, instrumented
ok 99 - cond_A1 not instrumented
ok 100 - cond_A1 not instrumented
ok 101 - file_A1 not instrumented
ok 102 - file_A1 not instrumented
ok 103 - file_A1 not instrumented
ok 104 - lost a file handle
ok 105 - file_A1 instrumented
ok 106 - file key 0 not instrumented
ok 107 - broken file key not instrumented
ok 108 - socket_A1 not instrumented
ok 109 - socket_A1 instrumented
ok 110 - socket_A1 not instrumented
ok 111 - socket_A1 not instrumented
ok 112 - mutex_A1 disabled, instrumented
ok 113 - mutex_A1 enabled, instrumented
ok 114 - mutex key 0 not instrumented
ok 115 - broken mutex key not instrumented
ok 116 - rwlock_A1 disabled, instrumented
ok 117 - rwlock_A1 enabled, instrumented
ok 118 - rwlock key 0 not instrumented
ok 119 - broken rwlock key not instrumented
ok 120 - cond_A1 disabled, instrumented
ok 121 - cond_A1 enabled, instrumented
ok 122 - cond key 0 not instrumented
ok 123 - broken cond key not instrumented
ok 124 - file_A1 not instrumented
ok 125 - file_A1 not instrumented
ok 126 - not instrumented
ok 127 - not instrumented
ok 128 - socket_A1 disabled, instrumented
ok 129 - socket_A1 enabled, instrumented
ok 130 - socket key 0 not instrumented
ok 131 - broken socket key not instrumented
# test_locker_disabled
ok 132 - T-1
ok 133 - mutex info A
ok 134 - rwlock info A
ok 135 - cond info A
ok 136 - file info A
ok 137 - socket info A
ok 138 - instrumented
ok 139 - instrumented
ok 140 - instrumented
ok 141 - instrumented
ok 142 - instrumented
ok 143 - no locker (T-1 disabled)
ok 144 - no locker (T-1 disabled)
ok 145 - no locker (T-1 disabled)
ok 146 - no locker (T-1 disabled)
ok 147 - no locker (T-1 disabled)
ok 148 - no locker (T-1 disabled)
ok 149 - no locker (T-1 disabled)
ok 150 - no locker (global disabled)
ok 151 - no locker (global disabled)
ok 152 - no locker (global disabled)
ok 153 - no locker (global disabled)
ok 154 - no locker (global disabled)
ok 155 - no locker (global disabled)
ok 156 - no locker (global disabled)
ok 157 - no locker (global counted)
ok 158 - no locker (global counted)
ok 159 - no locker (global counted)
ok 160 - locker (global counted)
ok 161 - locker (global counted)
ok 162 - locker (global counted)
ok 163 - no locker (global counted)
ok 164 - no locker
ok 165 - no locker
ok 166 - no locker
ok 167 - no locker
ok 168 - no locker
ok 169 - no locker
ok 170 - no locker
ok 171 - locker
ok 172 - locker
ok 173 - locker
ok 174 - locker
ok 175 - locker
ok 176 - locker
ok 177 - locker
ok 178 - instrumented
ok 179 - locker (owner not used)
ok 180 - no locker
ok 181 - no locker
ok 182 - no locker
ok 183 - no locker
ok 184 - no locker
ok 185 - no locker
ok 186 - no locker
# test_file_instrumentation_leak
ok 187 - T-1
ok 188 - file info A
ok 189 - file info B
ok 190 - locker
ok 191 - locker
ok 192 - locker
ok 193 - no locker, since the open was not instrumented
ok 194 - no locker, no leak
# test_event_name_index
ok 195 - bootstrap
ok 196 - psi
ok 197 - mutex class 1
ok 198 - index 4
ok 199 - mutex class 2
ok 200 - index 5
ok 201 - rwlock class 1
ok 202 - index 14
ok 203 - rwlock class 2
ok 204 - index 15
ok 205 - cond class 1
ok 206 - index 34
ok 207 - cond class 2
ok 208 - index 35
ok 209 - file class 1
ok 210 - index 74
ok 211 - file class 2
ok 212 - index 75
ok 213 - socket class 1
ok 214 - index 154
ok 215 - socket class 2
ok 216 - index 155
ok 217 - index 0
ok 218 - index 1
ok 219 - 314 event names
# test_memory_instruments
ok 220 - T-1
ok 221 - memory info A
ok 222 - alloc memory info A
ok 223 - realloc memory info A
ok 224 - realloc up memory info A
ok 225 - realloc down memory info A
ok 226 - alloc memory info A
ok 227 - realloc memory info A
ok 228 - realloc up memory info A
ok 229 - realloc down memory info A
ok 230 - alloc with unknown key
ok 231 - realloc with unknown key
ok 232 - bootstrap
[25 Jan 2018 10:52] Yura Sorokin
Suggested patch (resubmitted to the contribution section)

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

Contribution: bug89384.diff (application/octet-stream, text), 971 bytes.

[1 Jun 2018 18:36] Paul DuBois
Posted by developer:
 
Fixed in 5.6.41, 5.7.23, 8.0.12.

A memory leak in the pfs-t unit test was fixed. Thanks to Yura
Sorokin for the patch.