lantiq: ltq-vdsl-app: add dsl_cpe_pipe.sh
[lede.git] / package / network / config / swconfig / src / swlib.c
index 7de3a604e0760010a1a9729dff26e11ed69efd08..0dbace551ec887d14de041526e70d04f6cbd331f 100644 (file)
@@ -206,7 +206,6 @@ store_val(struct nl_msg *msg, void *arg)
 {
        struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
        struct switch_val *val = arg;
-       struct switch_attr *attr = val->attr;
 
        if (!val)
                goto error;
@@ -364,7 +363,7 @@ int swlib_set_attr_string(struct switch_dev *dev, struct switch_attr *a, int por
                val.value.i = atoi(str);
                break;
        case SWITCH_TYPE_STRING:
-               val.value.s = str;
+               val.value.s = (char *)str;
                break;
        case SWITCH_TYPE_PORTS:
                ports = alloca(sizeof(struct switch_port) * dev->ports);
@@ -530,10 +529,13 @@ struct switch_attr *swlib_lookup_attr(struct switch_dev *dev,
 static void
 swlib_priv_free(void)
 {
+       if (family)
+               nl_object_put((struct nl_object*)family);
        if (cache)
                nl_cache_free(cache);
        if (handle)
                nl_socket_free(handle);
+       family = NULL;
        handle = NULL;
        cache = NULL;
 }
@@ -669,11 +671,7 @@ done:
 static int
 list_switch(struct nl_msg *msg, void *arg)
 {
-       struct swlib_scan_arg *sa = arg;
        struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
-       struct switch_dev *dev;
-       const char *name;
-       const char *alias;
 
        if (nla_parse(tb, SWITCH_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL) < 0)
                goto done;
@@ -729,7 +727,6 @@ struct switch_dev *
 swlib_connect(const char *name)
 {
        struct swlib_scan_arg arg;
-       int err;
 
        if (!refcount) {
                if (swlib_priv_init() < 0)
@@ -755,18 +752,36 @@ swlib_free_attributes(struct switch_attr **head)
 
        while (a) {
                next = a->next;
+               free(a->name);
+               free(a->description);
                free(a);
                a = next;
        }
        *head = NULL;
 }
 
+static void
+swlib_free_port_map(struct switch_dev *dev)
+{
+       int i;
+
+       if (!dev || !dev->maps)
+               return;
+
+       for (i = 0; i < dev->ports; i++)
+               free(dev->maps[i].segment);
+       free(dev->maps);
+}
+
 void
 swlib_free(struct switch_dev *dev)
 {
        swlib_free_attributes(&dev->ops);
        swlib_free_attributes(&dev->port_ops);
        swlib_free_attributes(&dev->vlan_ops);
+       swlib_free_port_map(dev);
+       free(dev->name);
+       free(dev->alias);
        free(dev);
 
        if (--refcount == 0)