OSDN Git Service

hciops: Fix memory leak when loading keys
authorVinicius Costa Gomes <vinicius.gomes@openbossa.org>
Tue, 24 Jan 2012 00:21:51 +0000 (21:21 -0300)
committerJohan Hedberg <johan.hedberg@intel.com>
Tue, 24 Jan 2012 12:59:09 +0000 (14:59 +0200)
If we need a copy of those keys we should copy them.

plugins/hciops.c

index d4d219c..f4af637 100644 (file)
@@ -3563,6 +3563,7 @@ static int hciops_restore_powered(int index)
 static int hciops_load_keys(int index, GSList *keys, gboolean debug_keys)
 {
        struct dev_info *dev = &devs[index];
+       GSList *l;
 
        DBG("hci%d keys %d debug_keys %d", index, g_slist_length(keys),
                                                                debug_keys);
@@ -3570,7 +3571,16 @@ static int hciops_load_keys(int index, GSList *keys, gboolean debug_keys)
        if (dev->keys != NULL)
                return -EEXIST;
 
-       dev->keys = keys;
+       for (l = keys; l; l = l->next) {
+               struct link_key_info *orig, *dup;
+
+               orig = l->data;
+
+               dup = g_memdup(orig, sizeof(*orig));
+
+               dev->keys = g_slist_prepend(dev->keys, dup);
+       }
+
        dev->debug_keys = debug_keys;
 
        return 0;