routing: remove rt_entry.rt_best pointer when rt_path is deleted (#61)
authoriwanovich <iwanovich@users.noreply.github.com>
Wed, 23 May 2018 21:04:18 +0000 (23:04 +0200)
committerFerry Huberts <mailings@hupie.com>
Wed, 23 May 2018 21:04:18 +0000 (23:04 +0200)
routing: remove rt_entry.rt_best pointer when rt_path is deleted

When rt_path is free'd from memory, references to it should be deleted.

Checking all rt_entry structs for rt_best pointers to the rt_path
that is to be deleted and nullify the pointer. Not doing so might
lead to segfaults.

Signed-off-by: Iwan G. Flameling <iwanovich@gmail.com>
src/routing_table.c

index 454eef2..7d25ff5 100644 (file)
@@ -352,6 +352,7 @@ olsr_insert_rt_path(struct rt_path *rtp, struct tc_entry *tc, struct link_entry
 void
 olsr_delete_rt_path(struct rt_path *rtp)
 {
+  struct rt_entry* rt;
 
   /* remove from the originator tree */
   if (rtp->rtp_rt) {
@@ -371,6 +372,14 @@ olsr_delete_rt_path(struct rt_path *rtp)
     current_inetgw = NULL;
   }
 
+  /* remove reference from rt_best */
+  OLSR_FOR_ALL_RT_ENTRIES(rt)
+  if (rt->rt_best == rtp){
+    rt->rt_best = NULL;
+    OLSR_PRINTF(7, "Removed rt_best.\n");
+  }
+  OLSR_FOR_ALL_RT_ENTRIES_END(rt)
+
   olsr_cookie_free(rtp_mem_cookie, rtp);
 }