OSDN Git Service

obexd/service: Fix possible leaking drivers list
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 25 Sep 2013 08:32:19 +0000 (11:32 +0300)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 25 Sep 2013 08:40:12 +0000 (11:40 +0300)
When registering a new driver with obex_service_driver_register there
could exist another driver for the service which will cause the drivers
list to leak.

obexd/src/service.c

index 4d9ebfd..6b8533b 100644 (file)
@@ -81,14 +81,30 @@ GSList *obex_service_driver_list(uint16_t services)
        return list;
 }
 
+static struct obex_service_driver *find_driver(uint16_t service)
+{
+       GSList *l;
+
+       for (l = drivers; l; l = l->next) {
+               struct obex_service_driver *driver = l->data;
+
+               if (driver->service == service)
+                       return driver;
+       }
+
+       return NULL;
+}
+
 int obex_service_driver_register(struct obex_service_driver *driver)
 {
+       GSList *l;
+
        if (!driver) {
                error("Invalid driver");
                return -EINVAL;
        }
 
-       if (obex_service_driver_list(driver->service)) {
+       if (find_driver(driver->service)) {
                error("Permission denied: service %s already registered",
                        driver->name);
                return -EPERM;