summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2006-04-10 17:28:47 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2006-04-10 17:28:47 +0000
commit1f98ca9b57ecd36d032449972b7b9f006ad1e06f (patch)
tree93902fb3eb844f7cc70107f78423b294ec9ed9cf
parent99ab0e609a4590d0027ae42d95ed1ca0b6c2e86f (diff)
Fixed discoverable timeout and timeout list data memory leak
-rw-r--r--common/glib-ectomy.c9
-rw-r--r--hcid/dbus-adapter.c8
-rw-r--r--hcid/dbus-todo.txt10
-rw-r--r--hcid/dbus.c21
-rw-r--r--hcid/dbus.h4
5 files changed, 46 insertions, 6 deletions
diff --git a/common/glib-ectomy.c b/common/glib-ectomy.c
index f1d79e7f..7644fd18 100644
--- a/common/glib-ectomy.c
+++ b/common/glib-ectomy.c
@@ -133,6 +133,14 @@ guint g_io_add_watch(GIOChannel *channel, GIOCondition condition,
func, user_data, NULL);
}
+static void timeout_free(void *data, void *user_data)
+{
+ struct timeout *t = data;
+
+ if (t)
+ free (t);
+}
+
static GMainContext *g_main_context_default()
{
@@ -310,6 +318,7 @@ void g_main_loop_unref(GMainLoop *loop)
if (!loop->context)
return;
+ slist_foreach(loop->context->ltimeout, timeout_free, NULL);
slist_free(loop->context->ltimeout);
free(loop->context);
}
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c
index 3de4b9b1..ecfe0198 100644
--- a/hcid/dbus-adapter.c
+++ b/hcid/dbus-adapter.c
@@ -386,6 +386,14 @@ static DBusHandlerResult handle_dev_set_discoverable_to_req(DBusConnection *conn
return error_invalid_arguments(conn, msg);
}
+ if (dbus_data->timeout_id) {
+ g_timeout_remove(dbus_data->timeout_id);
+ dbus_data->timeout_id = 0;
+ }
+
+ if ((timeout != 0) && (dbus_data->mode & SCAN_INQUIRY))
+ dbus_data->timeout_id = g_timeout_add(timeout, discoverable_timeout_handler, dbus_data);
+
dbus_data->discoverable_timeout = timeout;
reply = dbus_message_new_method_return(msg);
diff --git a/hcid/dbus-todo.txt b/hcid/dbus-todo.txt
index e69de29b..beec2862 100644
--- a/hcid/dbus-todo.txt
+++ b/hcid/dbus-todo.txt
@@ -0,0 +1,10 @@
+* method rename
+Date: 2006/04/10
+Description: Rename the method GetServicesClasses to GetServiceClasses.
+
+* Error return for remote major/minor class
+Date: 2006/04/10
+Description: GetRemoteMajorMajorClass and GetRemoteMinorClass should
+return "org.bluez.Error.NotAvailable" when the "classes" doesn't exists.
+Currently, it's returning no such file or directory.
+
diff --git a/hcid/dbus.c b/hcid/dbus.c
index 3fed5397..b5928367 100644
--- a/hcid/dbus.c
+++ b/hcid/dbus.c
@@ -388,6 +388,8 @@ static gboolean unregister_dbus_path(const char *path)
slist_free(pdata->active_conn);
pdata->active_conn = NULL;
}
+
+ free (pdata);
}
if (!dbus_connection_unregister_object_path (connection, path)) {
@@ -1397,9 +1399,9 @@ done:
*
*****************************************************************/
-static int discoverable_timeout_handler(void *data)
+int discoverable_timeout_handler(void *data)
{
- const struct hci_dbus_data *dbus_data = data;
+ struct hci_dbus_data *dbus_data = data;
struct hci_request rq;
int dd = -1;
uint8_t hci_mode = dbus_data->mode;
@@ -1432,6 +1434,7 @@ static int discoverable_timeout_handler(void *data)
goto failed;
}
+ dbus_data->timeout_id = 0;
retval = -1;
failed:
if (dd >= 0)
@@ -1642,10 +1645,14 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local)
error("Getting %s path data failed!", path);
goto failed;
}
-
+
/* update the current scan mode value */
pdata->mode = rp.enable;
+ if (pdata->timeout_id) {
+ g_timeout_remove(pdata->timeout_id);
+ pdata->timeout_id = 0;
+ }
switch (rp.enable) {
case SCAN_DISABLED:
scan_mode = MODE_OFF;
@@ -1655,11 +1662,15 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local)
break;
case (SCAN_PAGE | SCAN_INQUIRY):
scan_mode = MODE_DISCOVERABLE;
- g_timeout_add(pdata->discoverable_timeout, discoverable_timeout_handler, pdata);
+ if (pdata->discoverable_timeout != 0)
+ pdata->timeout_id = g_timeout_add(pdata->discoverable_timeout,
+ discoverable_timeout_handler, pdata);
break;
case SCAN_INQUIRY:
/* Address the scenario where another app changed the scan mode */
- g_timeout_add(pdata->discoverable_timeout, discoverable_timeout_handler, pdata);
+ if (pdata->discoverable_timeout != 0)
+ pdata->timeout_id = g_timeout_add(pdata->discoverable_timeout,
+ discoverable_timeout_handler, pdata);
/* ignore, this event should not be sent*/
default:
/* ignore, reserved */
diff --git a/hcid/dbus.h b/hcid/dbus.h
index 5ae2b7b8..677c3220 100644
--- a/hcid/dbus.h
+++ b/hcid/dbus.h
@@ -105,7 +105,8 @@ struct active_conn_info {
struct hci_dbus_data {
uint16_t dev_id;
uint16_t path_id;
- uint32_t discoverable_timeout;
+ uint32_t timeout_id; /* discoverable timeout id */
+ uint32_t discoverable_timeout; /* discoverable time(msec) */
uint8_t mode; /* scan mode */
discover_state_t discover_state; /* discover states */
int discover_type; /* with/without name resolving */
@@ -198,6 +199,7 @@ void disc_device_info_free(void *data, void *user_data);
int disc_device_append(struct slist **list, bdaddr_t *bdaddr, name_status_t name_status);
int disc_device_req_name(struct hci_dbus_data *dbus_data);
+int discoverable_timeout_handler(void *data);
/*
* Scanning modes, used by DEV_SET_MODE
* off: remote devices are not allowed to find or connect to this device