interface: fix memleak and reload issue for the zone attribute
authorFelix Fietkau <nbd@nbd.name>
Tue, 17 Dec 2024 13:23:05 +0000 (14:23 +0100)
committerFelix Fietkau <nbd@nbd.name>
Tue, 17 Dec 2024 13:23:06 +0000 (14:23 +0100)
- consider the field in the reload codepath
- free the attribute on interface free

Signed-off-by: Felix Fietkau <nbd@nbd.name>
interface.c
interface.h

index 3fcfc79eae4ccf519c4ecf0899e5a00a1fe24522..ff4289be33ccfb2ff2b841903fb0a3ad06239a4e 100644 (file)
@@ -710,6 +710,7 @@ interface_do_free(struct interface *iface)
        free(iface->config);
        netifd_ubus_remove_interface(iface);
        avl_delete(&interfaces.avl, &iface->node.avl);
+       free(iface->zone);
        if (iface->jail)
                free(iface->jail);
        if (iface->jail_device)
@@ -1332,6 +1333,12 @@ interface_change_config(struct interface *if_old, struct interface *if_new)
                if_old->autostart = if_new->config_autostart;
        }
 
+       if (FIELD_CHANGED_STR(zone)) {
+               free(if_old->zone);
+               if_old->zone = if_new->zone;
+               reload = true;
+       }
+
        if_old->device_config = if_new->device_config;
        if_old->config_autostart = if_new->config_autostart;
        if (if_old->jail)
index 08d74eb10b65e29153f2f5c598f8a9e9785900bb..c12a266eb55009d4d89d069f006ba8c79f4748b3 100644 (file)
@@ -108,7 +108,7 @@ struct interface {
 
        const char *name;
        const char *device;
-       const char *zone;
+       char *zone;
        char *jail;
        char *jail_device;
        char *host_device;