interface: allocate and free memory for jail name
authorDaniel Golle <daniel@makrotopia.org>
Mon, 13 Apr 2020 15:24:25 +0000 (16:24 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Mon, 13 Apr 2020 16:36:24 +0000 (17:36 +0100)
Memory returned by blogmsg_get_string() is volatile, hence use strdup()
to have a permanent copy of the returned string and free it when no
longer needed.

Fixes: 1321c1b ("add basic support for jail network namespaces")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
interface.c
interface.h

index f661cfe22762cfb4e39a9d13eb4098dd8e7272a2..51f6e51174341416278a6cb2bfae5a4ac3cad4c4 100644 (file)
@@ -684,6 +684,9 @@ interface_do_free(struct interface *iface)
        free(iface->config);
        netifd_ubus_remove_interface(iface);
        avl_delete(&interfaces.avl, &iface->node.avl);
+       if (iface->jail)
+               free(iface->jail);
+
        free(iface);
 }
 
@@ -893,7 +896,7 @@ interface_alloc(const char *name, struct blob_attr *config, bool dynamic)
        iface->jail = NULL;
 
        if ((cur = tb[IFACE_ATTR_JAIL])) {
-               iface->jail = blobmsg_get_string(cur);
+               iface->jail = strdup(blobmsg_get_string(cur));
                iface->autostart = false;
        }
 
@@ -1325,6 +1328,9 @@ interface_change_config(struct interface *if_old, struct interface *if_new)
 
        if_old->device_config = if_new->device_config;
        if_old->config_autostart = if_new->config_autostart;
+       if (if_old->jail)
+               free(if_old->jail);
+
        if_old->jail = if_new->jail;
        if (if_old->jail)
                if_old->autostart = false;
index 0d384efec23db6aa8c0417d83be57bb816445717..cd09812ff137b5bef9f9813bbb91c6fa5690a030 100644 (file)
@@ -108,7 +108,7 @@ struct interface {
 
        const char *name;
        const char *ifname;
-       const char *jail;
+       char *jail;
        int netns_fd;
 
        bool available;