]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Linpool: Fix lp_restore()
authorMaria Matejka <mq@ucw.cz>
Thu, 20 Apr 2023 17:33:00 +0000 (19:33 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Thu, 20 Apr 2023 17:33:00 +0000 (19:33 +0200)
When lp_save() is called on an empty linpool, then some allocation is
done, then lp_restore() is called, the linpool is restored but the used
chunks are inaccessible. Fix it.

lib/mempool.c

index 7c306e991b7ec0204882d971471d963a5c83e1f1..9d4404f7cab4c567c01e625324400ad35385f89b 100644 (file)
@@ -240,9 +240,9 @@ lp_restore(linpool *m, lp_state *p)
   struct lp_chunk *c;
 
   /* Move ptr to the saved pos and free all newer large chunks */
-  m->current = c = p->current;
-  m->ptr = p->ptr;
-  m->end = c ? c->data + LP_DATA_SIZE : NULL;
+  m->current = c = p->current ?: m->first;
+  m->ptr = p->ptr ?: (c ? c->data : NULL);
+  m->end = c ? (c->data + LP_DATA_SIZE) : NULL;
   m->total_large = p->total_large;
 
   while ((c = m->first_large) && (c != p->large))