diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-03-14 21:35:31 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-03-14 21:35:31 +0000 |
commit | 7b8a634126a3aa79e08d9d35d207f55016f9bda9 (patch) | |
tree | ca5e49960f8d39e57cefee0613e86e360b279392 | |
parent | 405c12ea958b4ad04fc416a39d4ec6e64f6f991d (diff) |
added slist_foreach function and fixed small memory leak
-rw-r--r-- | common/list.c | 9 | ||||
-rw-r--r-- | common/list.h | 2 | ||||
-rw-r--r-- | hcid/dbus-adapter.c | 8 | ||||
-rw-r--r-- | hcid/dbus.c | 2 |
4 files changed, 20 insertions, 1 deletions
diff --git a/common/list.c b/common/list.c index c6d8cb98..31ae9d35 100644 --- a/common/list.c +++ b/common/list.c @@ -99,6 +99,15 @@ struct slist *slist_find(struct slist *list, const void *data, return NULL; } +void slist_foreach(struct slist *list, slist_func_t func, void *user_data) +{ + while (list) { + struct slist *next = list->next; + func(list->data, user_data); + list = next; + } +} + void slist_free(struct slist *list) { struct slist *l, *next; diff --git a/common/list.h b/common/list.h index 1838370c..026d470c 100644 --- a/common/list.h +++ b/common/list.h @@ -31,6 +31,7 @@ struct slist { }; typedef int (*cmp_func_t)(const void *a, const void *b); +typedef void (*slist_func_t)(void *data, void *user_data); struct slist *slist_append(struct slist *list, void *data); @@ -39,6 +40,7 @@ struct slist *slist_remove(struct slist *list, void *data); struct slist *slist_find(struct slist *list, const void *data, cmp_func_t cmp_func); +void slist_foreach(struct slist *list, slist_func_t func, void *user_data); void slist_free(struct slist *list); #endif /* __LIST_H */ diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index d3a6e613..50a9bb7a 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -41,6 +41,7 @@ #include "textfile.h" #include "oui.h" +#include "list.h" static const char *service_cls[] = { "positioning", @@ -72,6 +73,12 @@ static const char *phone_minor_cls[] = { "isdn" }; +static void remote_name_data_free(void *data, void *user_data) +{ + bdaddr_t *addr = data; + bt_free(addr); +} + static DBusHandlerResult handle_dev_get_address_req(DBusConnection *conn, DBusMessage *msg, void *data) { struct hci_dbus_data *dbus_data = data; @@ -1273,6 +1280,7 @@ static DBusHandlerResult handle_dev_cancel_discovery_req(DBusConnection *conn, D break; } + slist_foreach(dbus_data->discovered_devices, remote_name_data_free, NULL); slist_free(dbus_data->discovered_devices); dbus_data->discovered_devices = NULL; diff --git a/hcid/dbus.c b/hcid/dbus.c index 2b7ba72b..30c01b01 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -148,7 +148,7 @@ static int remote_name_remove(struct slist **list, bdaddr_t *addr) free(data); ret_val = 0; } - + return ret_val; } |