Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cd_client_connect_cb(): do not leak strings #14

Merged
merged 1 commit into from
May 26, 2015
Merged

cd_client_connect_cb(): do not leak strings #14

merged 1 commit into from
May 26, 2015

Conversation

LebedevRI
Copy link
Contributor

I was working on fixing leaks in darktable, and found this.

I have installed colord with this change into /usr/local, and verified that this fixes the LeakSanitizer complaint, makes darktable free of leaks in colord (or, at least i was not able to trigger others...) and does not seem to cause any side-effects (at least so far).

The reason is: client->priv is re-used several times, and cd_client_finalize()
is called only once at the end, so if cd_client_connect_cb() is called more
than once, it will re-duplicate those 3 strings, and the memory allocated
previously will leak.

Fixes several following LeakSanitizer-detected leaks like:

Direct leak of 23 byte(s) in 1 object(s) allocated from:
    0 0x7f647ff0474f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5474f)
    1 0x7f647d29f799 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4f799)
    2 0x7f647d2b812e in g_strdup (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x6812e)

    3 0x7f6478cce792 in cd_client_connect_cb /home/lebedevri/src/colord/lib/colord/cd-client.c:382
or
    3 0x7f6478cce822 in cd_client_connect_cb /home/lebedevri/src/colord/lib/colord/cd-client.c:388
or
    3 0x7f6478cce8b9 in cd_client_connect_cb /home/lebedevri/src/colord/lib/colord/cd-client.c:392

    4 0x7f647d82cdf6 in g_simple_async_result_complete (/usr/lib/x86_64-linux-gnu/libgio-2.0.so.0+0x74df6)
    5 0x7f647d82ce58 (/usr/lib/x86_64-linux-gnu/libgio-2.0.so.0+0x74e58)
    6 0x7f647d299b4c in g_main_context_dispatch (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x49b4c)
    7 0x7f647d299f1f (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x49f1f)
    8 0x7f647d29a241 in g_main_loop_run (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4a241)
    9 0x7f647f043bf4 in gtk_main (/usr/lib/x86_64-linux-gnu/libgtk-3.so.0+0x1ebbf4)
    10 0x7f647fa17eab in dt_gui_gtk_run /home/lebedevri/darktable/src/gui/gtk.c:964
    11 0x400cd3 in main /home/lebedevri/darktable/src/main.c:25
    12 0x7f6477ff9b44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b44)
    13 0x400bb8 (/usr/local/bin/darktable+0x400bb8)

… strings.

The reason is: client->priv is re-used several times, and cd_client_finalize()
is called only once at the end, so if cd_client_connect_cb() is called more
than once, it will re-duplicate those 3 strings, and the memory allocated
previously will leak.

Fixes several following LeakSanitizer-detected leaks like:
Direct leak of 23 byte(s) in 1 object(s) allocated from:
    0 0x7f647ff0474f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5474f)
    1 0x7f647d29f799 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4f799)
    2 0x7f647d2b812e in g_strdup (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x6812e)

    3 0x7f6478cce792 in cd_client_connect_cb /home/lebedevri/src/colord/lib/colord/cd-client.c:382
or
    3 0x7f6478cce822 in cd_client_connect_cb /home/lebedevri/src/colord/lib/colord/cd-client.c:388
or
    3 0x7f6478cce8b9 in cd_client_connect_cb /home/lebedevri/src/colord/lib/colord/cd-client.c:392

    4 0x7f647d82cdf6 in g_simple_async_result_complete (/usr/lib/x86_64-linux-gnu/libgio-2.0.so.0+0x74df6)
    5 0x7f647d82ce58 (/usr/lib/x86_64-linux-gnu/libgio-2.0.so.0+0x74e58)
    6 0x7f647d299b4c in g_main_context_dispatch (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x49b4c)
    7 0x7f647d299f1f (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x49f1f)
    8 0x7f647d29a241 in g_main_loop_run (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4a241)
    9 0x7f647f043bf4 in gtk_main (/usr/lib/x86_64-linux-gnu/libgtk-3.so.0+0x1ebbf4)
    10 0x7f647fa17eab in dt_gui_gtk_run /home/lebedevri/darktable/src/gui/gtk.c:964
    11 0x400cd3 in main /home/lebedevri/darktable/src/main.c:25
    12 0x7f6477ff9b44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b44)
    13 0x400bb8 (/usr/local/bin/darktable+0x400bb8)
hughsie added a commit that referenced this pull request May 26, 2015
…k-strings

cd_client_connect_cb(): do not leak strings
@hughsie hughsie merged commit 039aa5a into hughsie:master May 26, 2015
@LebedevRI LebedevRI deleted the cd_client_connect_cb-do-not-leak-strings branch May 26, 2015 20:50
@ht990332 ht990332 mentioned this pull request May 26, 2017
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants