Commit 385b3ea3 authored by Maria Matejka's avatar Maria Matejka
Browse files

For safer memory allocations, resources are bound to loops.

Also all loops have their basic resource pool for allocations which are
auto-freed when the loop is stopping.
parent ab0994a1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ int undo_available; /* Undo was not requested from last reconfiguration */
struct config *
config_alloc(const char *name)
{
  pool *p = rp_new(&root_pool, "Config");
  pool *p = rp_new(&root_pool, &main_birdloop, "Config");
  linpool *l = lp_new_default(p);
  struct config *c = lp_allocz(l, sizeof(struct config));

@@ -196,7 +196,7 @@ void
config_free(struct config *c)
{
  if (c)
    rfree(c->pool);
    rp_free(c->pool, &root_pool);
}

void
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ start_conf_env(void)
{
  bt_bird_init();

  pool *p = rp_new(&root_pool, "helper_pool");
  pool *p = rp_new(&root_pool, &main_birdloop, "helper_pool");
  linpool *l = lp_new_default(p);
  cfg_mem = l;
}
+1 −1
Original line number Diff line number Diff line
@@ -57,8 +57,8 @@ t_ev_run_list(void)

  resource_sys_init();
  resource_init();
  olock_init();
  birdloop_init();
  olock_init();
  io_init();
  rt_init();
  if_init();
+5 −3
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@

#include "test/birdtest.h"
#include "lib/flowspec.h"
#include "lib/io-loop.h"

#define NET_ADDR_FLOW4_(what,prefix,pxlen,data_)	\
  do 							\
@@ -446,8 +447,6 @@ t_validation6(void)
static int
t_builder4(void)
{
  resource_init();

  struct flow_builder *fb = flow_builder_init(&root_pool);
  linpool *lp = lp_new_default(&root_pool);

@@ -529,7 +528,6 @@ t_builder6(void)
{
  net_addr_ip6 ip;

  resource_init();
  linpool *lp = lp_new_default(&root_pool);
  struct flow_builder *fb = flow_builder_init(&root_pool);
  fb->ipv6 = 1;
@@ -673,6 +671,9 @@ main(int argc, char *argv[])
{
  bt_init(argc, argv);
  resource_sys_init();
  resource_init();
  the_bird_lock();
  birdloop_init();

  bt_test_suite(t_read_length,  "Testing get NLRI length");
  bt_test_suite(t_write_length, "Testing set NLRI length");
@@ -688,5 +689,6 @@ main(int argc, char *argv[])
  bt_test_suite(t_formatting4,  "Formatting Flow Specification (IPv4) into text representation");
  bt_test_suite(t_formatting6,  "Formatting Flow Specification (IPv6) into text representation");

  the_bird_unlock();
  return bt_exit_value();
}
+4 −2
Original line number Diff line number Diff line
@@ -9,7 +9,9 @@
#undef LOCAL_DEBUG

#include "test/birdtest.h"
#include "test/bt-utils.h"

#include "lib/io-loop.h"
#include "lib/hash.h"

struct test_node {
@@ -61,8 +63,7 @@ dump_nodes(void)
static void
init_hash_(uint order)
{
  resource_init();
  my_pool = rp_new(&root_pool, "Test pool");
  my_pool = rp_new(&root_pool, &main_birdloop, "Test pool");

  HASH_INIT(hash, my_pool, order);

@@ -290,6 +291,7 @@ int
main(int argc, char *argv[])
{
  bt_init(argc, argv);
  bt_bird_init();

  bt_test_suite(t_insert_find, 		"HASH_INSERT and HASH_FIND");
  bt_test_suite(t_insert_find_random, 	"HASH_INSERT pseudo-random keys and HASH_FIND");
Loading