From: Adam Michalski Date: Tue, 8 Feb 2022 15:01:35 +0000 (+0100) Subject: gdbus, p2p-gdbus: fix a memory leak X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F70%2F270770%2F1;p=platform%2Fcore%2Fsystem%2Fdbus-tools.git gdbus, p2p-gdbus: fix a memory leak Upon encountering an 's' in a format string, `g_variant_get()` takes a pointer to a (gchar *) (i.e., (gchar **)) and sets it to a newly-allocated copy of the string. It's the user's responsibility to free up memory by using `g_free()`. Change-Id: Ieec7ca25af592dfcdcca34dbe288ea347b80b102 --- diff --git a/benchmark/gdbus.c b/benchmark/gdbus.c index 75dc701..ca334b5 100644 --- a/benchmark/gdbus.c +++ b/benchmark/gdbus.c @@ -105,8 +105,10 @@ static void handle_method_call (GDBusConnection *connection, if(++cnt == state->iters) {cnt = 0; g_main_loop_quit (state->main_loop); } - if(state->buf[0] != 'r') + if(state->buf[0] != 'r') { + g_free(state->buf); /* free memory allocated by g_variant_get */ return; + } if (state->is_lt) { if (raw_data_on) @@ -122,6 +124,8 @@ static void handle_method_call (GDBusConnection *connection, min = lt; } } + + g_free(state->buf); /* free memory allocated by g_variant_get */ } } diff --git a/benchmark/p2p-gdbus.c b/benchmark/p2p-gdbus.c index 01d28ed..661092e 100644 --- a/benchmark/p2p-gdbus.c +++ b/benchmark/p2p-gdbus.c @@ -91,8 +91,10 @@ static void handle_method_call(GDBusConnection *connection, g_main_loop_quit(state->main_loop); } - if (state->buf[0] != 'R') /* skip warm-up tries */ + if (state->buf[0] != 'R') { /* skip warm-up tries */ + g_free(state->buf); /* free memory allocated by g_variant_get */ return; + } if (state->is_lt) { if (state->verbose) @@ -121,6 +123,8 @@ static void handle_method_call(GDBusConnection *connection, else g_print("Client said: %s %s\n", state->buf, timestamp); } + + g_free(state->buf); /* free memory allocated by g_variant_get */ } static const GDBusInterfaceVTable interface_vtable = {