qemu-e2k/io
Matheus Tavares Bernardino c3a2c84ae3 io/channel-tls: plug memory leakage on GSource
This leakage can be seen through test-io-channel-tls:

$ ../configure --target-list=aarch64-softmmu --enable-sanitizers
$ make ./tests/unit/test-io-channel-tls
$ ./tests/unit/test-io-channel-tls

Indirect leak of 104 byte(s) in 1 object(s) allocated from:
    #0 0x7f81d1725808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x7f81d135ae98 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x57e98)
    #2 0x55616c5d4c1b in object_new_with_propv ../qom/object.c:795
    #3 0x55616c5d4a83 in object_new_with_props ../qom/object.c:768
    #4 0x55616c5c5415 in test_tls_creds_create ../tests/unit/test-io-channel-tls.c:70
    #5 0x55616c5c5a6b in test_io_channel_tls ../tests/unit/test-io-channel-tls.c:158
    #6 0x7f81d137d58d  (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x7a58d)

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f81d1725a06 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:153
    #1 0x7f81d1472a20 in gnutls_dh_params_init (/lib/x86_64-linux-gnu/libgnutls.so.30+0x46a20)
    #2 0x55616c6485ff in qcrypto_tls_creds_x509_load ../crypto/tlscredsx509.c:634
    #3 0x55616c648ba2 in qcrypto_tls_creds_x509_complete ../crypto/tlscredsx509.c:694
    #4 0x55616c5e1fea in user_creatable_complete ../qom/object_interfaces.c:28
    #5 0x55616c5d4c8c in object_new_with_propv ../qom/object.c:807
    #6 0x55616c5d4a83 in object_new_with_props ../qom/object.c:768
    #7 0x55616c5c5415 in test_tls_creds_create ../tests/unit/test-io-channel-tls.c:70
    #8 0x55616c5c5a6b in test_io_channel_tls ../tests/unit/test-io-channel-tls.c:158
    #9 0x7f81d137d58d  (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x7a58d)

...

SUMMARY: AddressSanitizer: 49143 byte(s) leaked in 184 allocation(s).

The docs for `g_source_add_child_source(source, child_source)` says
"source will hold a reference on child_source while child_source is
attached to it." Therefore, we should unreference the child source at
`qio_channel_tls_read_watch()` after attaching it to `source`. With this
change, ./tests/unit/test-io-channel-tls shows no leakages.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2023-03-14 13:41:21 +00:00
..
channel-buffer.c io: Add support for MSG_PEEK for socket channel 2023-02-06 19:22:56 +01:00
channel-command.c io: Add support for MSG_PEEK for socket channel 2023-02-06 19:22:56 +01:00
channel-file.c io: Add support for MSG_PEEK for socket channel 2023-02-06 19:22:56 +01:00
channel-null.c io: Add support for MSG_PEEK for socket channel 2023-02-06 19:22:56 +01:00
channel-socket.c win32: replace closesocket() with close() wrapper 2023-03-13 15:39:31 +04:00
channel-tls.c io/channel-tls: plug memory leakage on GSource 2023-03-14 13:41:21 +00:00
channel-util.c io: Fix Lesser GPL version number 2020-10-29 09:57:37 +00:00
channel-watch.c win32: avoid mixing SOCKET and file descriptor space 2023-03-13 15:39:31 +04:00
channel-websock.c io: Add support for MSG_PEEK for socket channel 2023-02-06 19:22:56 +01:00
channel.c io: Add support for MSG_PEEK for socket channel 2023-02-06 19:22:56 +01:00
dns-resolver.c build-sys: add HAVE_IPPROTO_MPTCP 2021-09-30 15:30:25 +02:00
meson.build io: add a QIOChannelNull equivalent to /dev/null 2022-06-22 18:11:21 +01:00
net-listener.c io/net-listener: Call the notifier during finalize 2021-06-08 19:36:17 +01:00
task.c io: Fix Lesser GPL version number 2020-10-29 09:57:37 +00:00
trace-events io: add a QIOChannelNull equivalent to /dev/null 2022-06-22 18:11:21 +01:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00