From: José Roberto de Souza Date: Fri, 21 Sep 2012 22:43:58 +0000 (+0000) Subject: edbus: Fix memory leak in X-Git-Tag: upstream/1.7.8~190 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5fc1dfdc7457dc327cc10d19f26e3de4da04a7b1;p=platform%2Fupstream%2Feldbus.git edbus: Fix memory leak in edbus_signal_handler_match_extra_set() And allow values == "" in match_extra_set() Patch by: José Roberto de Souza SVN revision: 77004 --- diff --git a/src/examples/banshee.c b/src/examples/banshee.c index 2134c26..389962f 100644 --- a/src/examples/banshee.c +++ b/src/examples/banshee.c @@ -141,11 +141,7 @@ on_name_owner_changed_by_id(void *data, const EDBus_Message *msg) if (!edbus_message_arguments_get(msg, "sss", &bus, &older_id, &new_id)) printf("Error getting arguments from NameOwnerChanged"); - printf("on_name_owner_changed_by_id bus = %s older=%s new=%s\n\n", - bus, older_id, new_id); - - if (!new_id[0]) - edbus_signal_handler_unref(sh3); + printf("banshee started on id=%s\n", new_id); } static void @@ -160,18 +156,6 @@ on_name_owner_changed(void *data, const EDBus_Message *msg) printf("Error getting arguments from NameOwnerChanged"); printf("bus = %s older=%s new=%s\n\n", bus, older_id, new_id); - - if (new_id[0]) - { - sh4 = edbus_signal_handler_add(conn, - EDBUS_FDO_BUS, - EDBUS_FDO_PATH, - EDBUS_FDO_INTERFACE, - "NameOwnerChanged", - on_name_owner_changed_by_id, - NULL); - edbus_signal_handler_match_extra_set(sh4, "arg1", new_id, NULL); - } } int @@ -276,6 +260,17 @@ main(void) NULL); edbus_signal_handler_match_extra_set(sh3, "arg0", "org.bansheeproject.Banshee", NULL); + sh4 = edbus_signal_handler_add(conn, + EDBUS_FDO_BUS, + EDBUS_FDO_PATH, + EDBUS_FDO_INTERFACE, + "NameOwnerChanged", + on_name_owner_changed_by_id, + NULL); + edbus_signal_handler_match_extra_set(sh4, + "arg0", "org.bansheeproject.Banshee", + "arg1", "", NULL); + ecore_timer_add(50, _timer1_cb, NULL); ecore_main_loop_begin(); diff --git a/src/lib/edbus_signal_handler.c b/src/lib/edbus_signal_handler.c index e852ba6..f5192db 100644 --- a/src/lib/edbus_signal_handler.c +++ b/src/lib/edbus_signal_handler.c @@ -51,7 +51,7 @@ edbus_signal_handler_shutdown(void) static void _match_append(Eina_Strbuf *match, const char *key, const char *value) { - if (value == NULL || !value[0]) return; + if (!value) return; if ((eina_strbuf_length_get(match) + strlen(",=''") + strlen(key) + strlen(value)) >= DBUS_MAXIMUM_MATCH_RULE_LENGTH) @@ -79,7 +79,7 @@ EAPI Eina_Bool edbus_signal_handler_match_extra_set(EDBus_Signal_Handler *sh, ...) { va_list ap; - char *key = NULL, *value; + char *key = NULL, *read; Signal_Argument *arg; DBusError err; @@ -91,30 +91,33 @@ edbus_signal_handler_match_extra_set(EDBus_Signal_Handler *sh, ...) EINA_SAFETY_ON_TRUE_RETURN_VAL(dbus_error_is_set(&err), EINA_FALSE); va_start(ap, sh); - do + for (read = va_arg(ap, char *); read; read = va_arg(ap, char *)) { if (!key) { - key = va_arg(ap, char *); + key = read; continue; } - value = va_arg(ap, char *); arg = calloc(1, sizeof(Signal_Argument)); EINA_SAFETY_ON_NULL_GOTO(arg, error); - if (!strncmp(key, ARGX, strlen(ARGX))) { - int id = atoi(key+strlen(ARGX)-1); - arg->index = (unsigned short)id; - arg->value = eina_stringshare_add(value); + int id = atoi(key + strlen(ARGX)); + arg->index = (unsigned short) id; + arg->value = eina_stringshare_add(read); sh->args = eina_inlist_sorted_state_insert(sh->args, EINA_INLIST_GET(arg), _sort_arg, sh->state_args); - _match_append(sh->match, key, value); + _match_append(sh->match, key, read); + } + else + { + ERR("%s not supported", key); + free(arg); } key = NULL; - } while(key); + } va_end(ap); dbus_error_init(&err);