sgw: fix memory leaks on the shutdown path
authorFerry Huberts <ferry.huberts@pelagic.nl>
Sat, 30 Apr 2016 16:16:31 +0000 (18:16 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Sat, 30 Apr 2016 20:41:03 +0000 (22:41 +0200)
Found with SANITIZE_LEAK=1

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
src/cfgparser/oparse.y
src/gateway.c

index 7072c52..e4d71d4 100644 (file)
@@ -1449,7 +1449,8 @@ sgw_egress_if: TOK_STRING
       }
       memset(in, 0, sizeof(*in));
 
-      in->name = str;
+      in->name = strdup(str);
+      free ($1->string);
     }
 
     last = olsr_cnf->smart_gw_egress_interfaces;
index 58c58e5..6e15989 100644 (file)
@@ -999,6 +999,13 @@ void olsr_cleanup_gateways(void) {
   struct gateway_entry * tree_gw;
   struct gw_container_entry * gw;
 
+  while (olsr_cnf->smart_gw_egress_interfaces) {
+    struct sgw_egress_if * next = olsr_cnf->smart_gw_egress_interfaces->next;
+    free(olsr_cnf->smart_gw_egress_interfaces->name);
+    free(olsr_cnf->smart_gw_egress_interfaces);
+    olsr_cnf->smart_gw_egress_interfaces = next;
+  }
+
   /* remove all gateways in the gateway tree that are not the active gateway */
   OLSR_FOR_ALL_GATEWAY_ENTRIES(tree_gw) {
     if ((tree_gw != olsr_get_inet_gateway(false)) && (tree_gw != olsr_get_inet_gateway(true))) {