Skip to content

Commit f0315a3

Browse files
committed
test_serial: Clean up after test case
Free all allocated memory to avoid false-positives from leak sanitizers. Resolves: ==15807==ERROR: LeakSanitizer: detected memory leaks Indirect leak of 4096 byte(s) in 1 object(s) allocated from: #0 0x7fb35b934f1e in __interceptor_realloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10df1e) #1 0x7fb35b7f3065 in __mctp_realloc /home/andrew/src/openbmc/libmctp/alloc.c:48 #2 0x7fb35b7ed979 in mctp_msg_ctx_add_pkt /home/andrew/src/openbmc/libmctp/core.c:213 #3 0x7fb35b7f0a09 in mctp_bus_rx /home/andrew/src/openbmc/libmctp/core.c:383 #4 0x7fb35b7f467d in mctp_serial_finish_packet /home/andrew/src/openbmc/libmctp/serial.c:169 #5 0x7fb35b7f6071 in mctp_rx_consume_one /home/andrew/src/openbmc/libmctp/serial.c:254 #6 0x7fb35b7f6409 in mctp_rx_consume /home/andrew/src/openbmc/libmctp/serial.c:271 #7 0x7fb35b7f668a in mctp_serial_read /home/andrew/src/openbmc/libmctp/serial.c:288 #8 0x559680986cc7 in main tests/test_serial.c:113 #9 0x7fb35ac9e1e2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x271e2) Indirect leak of 1384 byte(s) in 1 object(s) allocated from: #0 0x7fb35b934ae8 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10dae8) #1 0x7fb35b7f2cf0 in __mctp_alloc /home/andrew/src/openbmc/libmctp/alloc.c:28 #2 0x7fb35b7f6cad in mctp_serial_init /home/andrew/src/openbmc/libmctp/serial.c:343 #3 0x559680986553 in main tests/test_serial.c:99 #4 0x7fb35ac9e1e2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x271e2) Indirect leak of 552 byte(s) in 1 object(s) allocated from: #0 0x7fb35b934ae8 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10dae8) #1 0x7fb35b7f2cf0 in __mctp_alloc /home/andrew/src/openbmc/libmctp/alloc.c:28 #2 0x7fb35b7ededc in mctp_init /home/andrew/src/openbmc/libmctp/core.c:234 #3 0x559680986485 in main tests/test_serial.c:96 #4 0x7fb35ac9e1e2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x271e2) Indirect leak of 40 byte(s) in 1 object(s) allocated from: #0 0x7fb35b934ae8 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10dae8) #1 0x7fb35b7f2cf0 in __mctp_alloc /home/andrew/src/openbmc/libmctp/alloc.c:28 #2 0x7fb35b7ee55f in mctp_register_bus /home/andrew/src/openbmc/libmctp/core.c:277 #3 0x559680986b64 in main tests/test_serial.c:105 #4 0x7fb35ac9e1e2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x271e2) Signed-off-by: Andrew Jeffery <[email protected]> Change-Id: I9f95104545cc6f633ee134fffc90cb0ea2c46eeb
1 parent f8b4749 commit f0315a3

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tests/test_serial.c

+13-6
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ int main(void)
6565
{
6666
struct serial_test scenario[2];
6767

68-
struct mctp_binding_serial_pipe *a = &scenario[0].binding;
69-
struct mctp_binding_serial_pipe *b = &scenario[1].binding;
68+
struct mctp_binding_serial_pipe *a;
69+
struct mctp_binding_serial_pipe *b;
7070
int p[2][2];
7171
int rc;
7272

@@ -84,8 +84,9 @@ int main(void)
8484
/* Instantiate the A side of the serial pipe */
8585
scenario[0].mctp = mctp_init();
8686
assert(scenario[0].mctp);
87-
a->serial = mctp_serial_init();
88-
assert(a->serial);
87+
scenario[0].binding.serial = mctp_serial_init();
88+
assert(scenario[0].binding.serial);
89+
a = &scenario[0].binding;
8990
a->ingress = p[0][0];
9091
a->egress = p[1][1];
9192
mctp_serial_open_fd(a->serial, a->ingress);
@@ -96,8 +97,9 @@ int main(void)
9697
scenario[1].mctp = mctp_init();
9798
assert(scenario[1].mctp);
9899
mctp_set_rx_all(scenario[1].mctp, rx_message, NULL);
99-
b->serial = mctp_serial_init();
100-
assert(b->serial);
100+
scenario[1].binding.serial = mctp_serial_init();
101+
assert(scenario[1].binding.serial);
102+
b = &scenario[1].binding;
101103
b->ingress = p[1][0];
102104
b->egress = p[0][1];
103105
mctp_serial_open_fd(b->serial, b->ingress);
@@ -113,5 +115,10 @@ int main(void)
113115
mctp_serial_read(b->serial);
114116
assert(seen);
115117

118+
mctp_serial_destroy(scenario[1].binding.serial);
119+
mctp_destroy(scenario[1].mctp);
120+
mctp_serial_destroy(scenario[0].binding.serial);
121+
mctp_destroy(scenario[0].mctp);
122+
116123
return 0;
117124
}

0 commit comments

Comments
 (0)