summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-10-08 14:54:52 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-10-08 23:20:26 +0100
commitacee84c8eb31777bda51a93f01cae53abe81572a (patch)
treeb4c188a0644a33f05499b5a1148112e07d1a59a4 /src/modules
parenta0fc5a7c30d64d05b43c803b6bd2bfe11b6fd5e1 (diff)
bz5 - ensure we unref bluez dbus objects to free them
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/bluez5/bz.h1
-rw-r--r--src/modules/bluez5/bz_agent.c12
-rw-r--r--src/modules/bluez5/bz_obj.c58
3 files changed, 43 insertions, 28 deletions
diff --git a/src/modules/bluez5/bz.h b/src/modules/bluez5/bz.h
index 2d09997..63ebe00 100644
--- a/src/modules/bluez5/bz.h
+++ b/src/modules/bluez5/bz.h
@@ -13,6 +13,7 @@ typedef struct _Obj Obj;
13 13
14struct _Obj { 14struct _Obj {
15 //// internal object data 15 //// internal object data
16 Eldbus_Object *obj;
16 Eldbus_Proxy *proxy; 17 Eldbus_Proxy *proxy;
17 Eldbus_Proxy *prop_proxy; 18 Eldbus_Proxy *prop_proxy;
18 Eldbus_Signal_Handler *prop_sig; 19 Eldbus_Signal_Handler *prop_sig;
diff --git a/src/modules/bluez5/bz_agent.c b/src/modules/bluez5/bz_agent.c
index 8eb0489..066b7a0 100644
--- a/src/modules/bluez5/bz_agent.c
+++ b/src/modules/bluez5/bz_agent.c
@@ -2,6 +2,7 @@
2#include "e.h" 2#include "e.h"
3 3
4static Eldbus_Service_Interface *agent_iface = NULL; 4static Eldbus_Service_Interface *agent_iface = NULL;
5static Eldbus_Object *agent_obj = NULL;
5static Eldbus_Proxy *agent_proxy = NULL; 6static Eldbus_Proxy *agent_proxy = NULL;
6static void (*fn_release) (void) = NULL; 7static void (*fn_release) (void) = NULL;
7static void (*fn_cancel) (void) = NULL; 8static void (*fn_cancel) (void) = NULL;
@@ -149,6 +150,11 @@ cb_unregister(void *data EINA_UNUSED, const Eldbus_Message *msg,
149 eldbus_proxy_unref(agent_proxy); 150 eldbus_proxy_unref(agent_proxy);
150 agent_proxy = NULL; 151 agent_proxy = NULL;
151 } 152 }
153 if (agent_obj)
154 {
155 eldbus_object_unref(agent_obj);
156 agent_obj = NULL;
157 }
152 if (agent_iface) 158 if (agent_iface)
153 { 159 {
154 eldbus_service_object_unregister(agent_iface); 160 eldbus_service_object_unregister(agent_iface);
@@ -266,10 +272,8 @@ bz_agent_msg_u32_add(Eldbus_Message *msg, unsigned int u32)
266void 272void
267bz_agent_init(void) 273bz_agent_init(void)
268{ 274{
269 Eldbus_Object *obj; 275 agent_obj = eldbus_object_get(bz_conn, "org.bluez", "/org/bluez");
270 276 agent_proxy = eldbus_proxy_get(agent_obj, "org.bluez.AgentManager1");
271 obj = eldbus_object_get(bz_conn, "org.bluez", "/org/bluez");
272 agent_proxy = eldbus_proxy_get(obj, "org.bluez.AgentManager1");
273 agent_iface = eldbus_service_interface_register 277 agent_iface = eldbus_service_interface_register
274 (bz_conn, "/org/enlightenment/bluez5/agent", &agent_desc); 278 (bz_conn, "/org/enlightenment/bluez5/agent", &agent_desc);
275 if (agent_proxy) 279 if (agent_proxy)
diff --git a/src/modules/bluez5/bz_obj.c b/src/modules/bluez5/bz_obj.c
index 8bcf666..b61dc69 100644
--- a/src/modules/bluez5/bz_obj.c
+++ b/src/modules/bluez5/bz_obj.c
@@ -1,6 +1,7 @@
1#include "bz.h" 1#include "bz.h"
2#include "e_mod_main.h" 2#include "e_mod_main.h"
3 3
4static Eldbus_Object *objman_obj = NULL;
4static Eldbus_Proxy *objman_proxy = NULL; 5static Eldbus_Proxy *objman_proxy = NULL;
5static Eldbus_Signal_Handler *sig_ifadd = NULL; 6static Eldbus_Signal_Handler *sig_ifadd = NULL;
6static Eldbus_Signal_Handler *sig_ifdel = NULL; 7static Eldbus_Signal_Handler *sig_ifdel = NULL;
@@ -295,18 +296,16 @@ cb_obj_prop_changed(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSE
295Obj * 296Obj *
296bz_obj_add(const char *path) 297bz_obj_add(const char *path)
297{ 298{
298 Eldbus_Object *obj;
299
300 Obj *o = calloc(1, sizeof(Obj)); 299 Obj *o = calloc(1, sizeof(Obj));
301 o->ref = 1; 300 o->ref = 1;
302 o->path = eina_stringshare_add(path); 301 o->path = eina_stringshare_add(path);
303 obj = eldbus_object_get(bz_conn, "org.bluez", o->path); 302 o->obj = eldbus_object_get(bz_conn, "org.bluez", o->path);
304 o->type = BZ_OBJ_UNKNOWN; 303 o->type = BZ_OBJ_UNKNOWN;
305 o->in_table = EINA_TRUE; 304 o->in_table = EINA_TRUE;
306 eina_hash_add(obj_table, o->path, o); 305 eina_hash_add(obj_table, o->path, o);
307 if (!strcmp(o->path, "/org/bluez")) 306 if (!strcmp(o->path, "/org/bluez"))
308 { 307 {
309 o->proxy = eldbus_proxy_get(obj, "org.bluez.AgentManager1"); 308 o->proxy = eldbus_proxy_get(o->obj, "org.bluez.AgentManager1");
310 o->type = BZ_OBJ_BLUEZ; 309 o->type = BZ_OBJ_BLUEZ;
311 o->add_called = EINA_TRUE; 310 o->add_called = EINA_TRUE;
312 bz_obj_ref(o); 311 bz_obj_ref(o);
@@ -317,12 +316,12 @@ bz_obj_add(const char *path)
317 // all devices are /org/bluez/XXX/dev_XXX so look for /dev_ 316 // all devices are /org/bluez/XXX/dev_XXX so look for /dev_
318 else if (strstr(o->path, "/dev_")) 317 else if (strstr(o->path, "/dev_"))
319 { 318 {
320 o->proxy = eldbus_proxy_get(obj, "org.bluez.Device1"); 319 o->proxy = eldbus_proxy_get(o->obj, "org.bluez.Device1");
321 o->type = BZ_OBJ_DEVICE; 320 o->type = BZ_OBJ_DEVICE;
322 if (o->proxy) 321 if (o->proxy)
323 { 322 {
324 eldbus_proxy_property_get_all(o->proxy, cb_obj_prop, o); 323 eldbus_proxy_property_get_all(o->proxy, cb_obj_prop, o);
325 o->prop_proxy = eldbus_proxy_get(obj, 324 o->prop_proxy = eldbus_proxy_get(o->obj,
326 "org.freedesktop.DBus.Properties"); 325 "org.freedesktop.DBus.Properties");
327 if (o->prop_proxy) 326 if (o->prop_proxy)
328 o->prop_sig = eldbus_proxy_signal_handler_add(o->prop_proxy, 327 o->prop_sig = eldbus_proxy_signal_handler_add(o->prop_proxy,
@@ -334,12 +333,12 @@ bz_obj_add(const char *path)
334 // all dadapters begin with /org/bluez/ 333 // all dadapters begin with /org/bluez/
335 else if (!strncmp(o->path, "/org/bluez/", 11)) 334 else if (!strncmp(o->path, "/org/bluez/", 11))
336 { 335 {
337 o->proxy = eldbus_proxy_get(obj, "org.bluez.Adapter1"); 336 o->proxy = eldbus_proxy_get(o->obj, "org.bluez.Adapter1");
338 o->type = BZ_OBJ_ADAPTER; 337 o->type = BZ_OBJ_ADAPTER;
339 if (o->proxy) 338 if (o->proxy)
340 { 339 {
341 eldbus_proxy_property_get_all(o->proxy, cb_obj_prop, o); 340 eldbus_proxy_property_get_all(o->proxy, cb_obj_prop, o);
342 o->prop_proxy = eldbus_proxy_get(obj, 341 o->prop_proxy = eldbus_proxy_get(o->obj,
343 "org.freedesktop.DBus.Properties"); 342 "org.freedesktop.DBus.Properties");
344 if (o->prop_proxy) 343 if (o->prop_proxy)
345 o->prop_sig = eldbus_proxy_signal_handler_add(o->prop_proxy, 344 o->prop_sig = eldbus_proxy_signal_handler_add(o->prop_proxy,
@@ -742,16 +741,6 @@ bz_obj_unref(Obj *o)
742 eldbus_signal_handler_del(o->prop_sig); 741 eldbus_signal_handler_del(o->prop_sig);
743 o->prop_sig = NULL; 742 o->prop_sig = NULL;
744 } 743 }
745 if (o->proxy)
746 {
747 eldbus_proxy_unref(o->proxy);
748 o->proxy = NULL;
749 }
750 if (o->prop_proxy)
751 {
752 eldbus_proxy_unref(o->prop_proxy);
753 o->prop_proxy = NULL;
754 }
755 if (o->path) 744 if (o->path)
756 { 745 {
757 eina_stringshare_del(o->path); 746 eina_stringshare_del(o->path);
@@ -787,6 +776,21 @@ bz_obj_unref(Obj *o)
787 ecore_exe_free(o->ping_exe); 776 ecore_exe_free(o->ping_exe);
788 o->ping_exe = NULL; 777 o->ping_exe = NULL;
789 } 778 }
779 if (o->proxy)
780 {
781 eldbus_proxy_unref(o->proxy);
782 o->proxy = NULL;
783 }
784 if (o->prop_proxy)
785 {
786 eldbus_proxy_unref(o->prop_proxy);
787 o->prop_proxy = NULL;
788 }
789 if (o->obj)
790 {
791 eldbus_object_unref(o->obj);
792 o->obj = NULL;
793 }
790 free(o); 794 free(o);
791} 795}
792 796
@@ -894,12 +898,10 @@ _obj_hash_free(Obj *o)
894void 898void
895bz_obj_init(void) 899bz_obj_init(void)
896{ 900{
897 Eldbus_Object *obj;
898
899 obj_table = eina_hash_string_superfast_new((void *)_obj_hash_free); 901 obj_table = eina_hash_string_superfast_new((void *)_obj_hash_free);
900 902
901 obj = eldbus_object_get(bz_conn, "org.bluez", "/"); 903 objman_obj = eldbus_object_get(bz_conn, "org.bluez", "/");
902 objman_proxy = eldbus_proxy_get(obj, "org.freedesktop.DBus.ObjectManager"); 904 objman_proxy = eldbus_proxy_get(objman_obj, "org.freedesktop.DBus.ObjectManager");
903 sig_ifadd = eldbus_proxy_signal_handler_add(objman_proxy, "InterfacesAdded", 905 sig_ifadd = eldbus_proxy_signal_handler_add(objman_proxy, "InterfacesAdded",
904 cb_obj_add, NULL); 906 cb_obj_add, NULL);
905 sig_ifdel = eldbus_proxy_signal_handler_add(objman_proxy, "InterfacesRemoved", 907 sig_ifdel = eldbus_proxy_signal_handler_add(objman_proxy, "InterfacesRemoved",
@@ -928,8 +930,16 @@ bz_obj_shutdown(void)
928 eldbus_signal_handler_del(sig_ifdel); 930 eldbus_signal_handler_del(sig_ifdel);
929 sig_ifdel = NULL; 931 sig_ifdel = NULL;
930 } 932 }
931 eldbus_proxy_unref(objman_proxy); 933 if (objman_proxy)
932 objman_proxy = NULL; 934 {
935 eldbus_proxy_unref(objman_proxy);
936 objman_proxy = NULL;
937 }
938 if (objman_obj)
939 {
940 eldbus_object_unref(objman_obj);
941 objman_obj = NULL;
942 }
933} 943}
934 944
935void 945void