]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Birdlib: Do cleanups after remove/free
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 22 Mar 2016 12:35:40 +0000 (13:35 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Wed, 23 Mar 2016 01:21:42 +0000 (02:21 +0100)
To avoid byzantine behavior in case of some errors, linked lists are
cleared after rem_node() and resource headers are cleared after rfree().

lib/lists.c
lib/lists.h
lib/resource.c
proto/bfd/bfd.c

index d323a4b68d5bbb64a2f6d53199ee5c72a38619ac..20a9a0728e5ac158079c07afeb976ee07611a4ac 100644 (file)
@@ -88,7 +88,7 @@ insert_node(node *n, node *after)
  * rem_node - remove a node from a list
  * @n: node to be removed
  *
- * Removes a node @n from the list it's linked in.
+ * Removes a node @n from the list it's linked in. Afterwards, node @n is cleared.
  */
 LIST_INLINE void
 rem_node(node *n)
@@ -96,23 +96,6 @@ rem_node(node *n)
   node *z = n->prev;
   node *x = n->next;
 
-  z->next = x;
-  x->prev = z;
-}
-
-/**
- * rem2_node - remove a node from a list, with cleanup
- * @n: node to be removed
- *
- * Removes a node @n from the list it's linked in and resets its pointers to NULL.
- * Useful if you want to distinguish between linked and unlinked nodes.
- */
-LIST_INLINE void
-rem2_node(node *n)
-{
-  node *z = n->prev;
-  node *x = n->next;
-
   z->next = x;
   x->prev = z;
   n->next = NULL;
index 80a4dc93731e3b0835fbe6bea9e3c53726dd81f0..4204cbc5bec061f78ae066d807f7f2af02c5490a 100644 (file)
@@ -61,7 +61,6 @@ typedef struct list {                 /* In fact two overlayed nodes */
 void add_tail(list *, node *);
 void add_head(list *, node *);
 void rem_node(node *);
-void rem2_node(node *);
 void add_tail_list(list *, list *);
 void init_list(list *);
 void insert_node(node *, node *);
index 64f9a39cd36de0a1c7e388a35d1a0e7c8b5f0bae..68718dfb617cb4c4ba5f452af8c5ffe8776c0fc8 100644 (file)
@@ -163,6 +163,7 @@ rfree(void *res)
   if (r->n.next)
     rem_node(&r->n);
   r->class->free(r);
+  r->class = NULL;
   xfree(r);
 }
 
@@ -383,16 +384,9 @@ mb_allocz(pool *p, unsigned size)
 void *
 mb_realloc(void *m, unsigned size)
 {
-  struct mblock *ob = NULL;
-
-  if (m)
-    {
-      ob = SKIP_BACK(struct mblock, data, m);
-      if (ob->r.n.next)
-       rem_node(&ob->r.n);
-    }
+  struct mblock *b = SKIP_BACK(struct mblock, data, m);
 
-  struct mblock *b = xrealloc(ob, sizeof(struct mblock) + size);
+  b = xrealloc(b, sizeof(struct mblock) + size);
   replace_node(&b->r.n, &b->r.n);
   b->size = size;
   return b->data;
index 7a0857915292ca114fc43c5c8f49b01e553483d9..5de2f5563dcde08e699893da2a4f115b1ae49531 100644 (file)
@@ -872,7 +872,7 @@ bfd_notify_hook(sock *sk, int len)
   WALK_LIST_FIRST(s, tmp_list)
   {
     bfd_lock_sessions(p);
-    rem2_node(&s->n);
+    rem_node(&s->n);
     state = s->loc_state;
     diag = s->loc_diag;
     bfd_unlock_sessions(p);