Memory leak in load-balance maps

Change-Id: Iec67ae1232e346d5e0000e0b4c997fdc31865bc6
Signed-off-by: Neale Ranns <nranns@cisco.com>
This commit is contained in:
Neale Ranns
2017-04-18 12:56:45 -07:00
parent 68df5a51f6
commit d8d09d15e2
2 changed files with 20 additions and 5 deletions

View File

@ -415,6 +415,14 @@ load_balance_map_init (load_balance_map_t *lbm,
return (lbm); return (lbm);
} }
static void
load_balance_map_destroy (load_balance_map_t *lbm)
{
vec_free(lbm->lbm_paths);
vec_free(lbm->lbm_buckets);
pool_put(load_balance_map_pool, lbm);
}
index_t index_t
load_balance_map_add_or_lock (u32 n_buckets, load_balance_map_add_or_lock (u32 n_buckets,
u32 sum_of_weights, u32 sum_of_weights,
@ -434,6 +442,7 @@ load_balance_map_add_or_lock (u32 n_buckets,
else else
{ {
lbm = load_balance_map_get(lbmi); lbm = load_balance_map_get(lbmi);
load_balance_map_destroy(tmp);
} }
lbm->lbm_locks++; lbm->lbm_locks++;
@ -468,9 +477,7 @@ load_balance_map_unlock (index_t lbmi)
if (0 == lbm->lbm_locks) if (0 == lbm->lbm_locks)
{ {
load_balance_map_db_remove(lbm); load_balance_map_db_remove(lbm);
vec_free(lbm->lbm_paths); load_balance_map_destroy(lbm);
vec_free(lbm->lbm_buckets);
pool_put(load_balance_map_pool, lbm);
} }
} }

View File

@ -585,6 +585,7 @@ fib_test_v4 (void)
const load_balance_t *lb; const load_balance_t *lb;
test_main_t *tm; test_main_t *tm;
u32 fib_index; u32 fib_index;
int lb_count;
int ii; int ii;
/* via 10.10.10.1 */ /* via 10.10.10.1 */
@ -598,6 +599,9 @@ fib_test_v4 (void)
tm = &test_main; tm = &test_main;
/* record the nubmer of load-balances in use before we start */
lb_count = pool_elts(load_balance_pool);
/* Find or create FIB table 11 */ /* Find or create FIB table 11 */
fib_index = fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP4, 11); fib_index = fib_table_find_or_create_and_lock(FIB_PROTOCOL_IP4, 11);
@ -3022,7 +3026,7 @@ fib_test_v4 (void)
"LB maps's bucket 1 is %d", "LB maps's bucket 1 is %d",
lbm->lbm_buckets[1]); lbm->lbm_buckets[1]);
load_balance_map_unlock(lb->lb_map); load_balance_map_unlock(lbmi);
/* /*
* add it back. again * add it back. again
@ -3117,7 +3121,7 @@ fib_test_v4 (void)
"LB Map for 200.200.200.200/32 at %d is %d", "LB Map for 200.200.200.200/32 at %d is %d",
ii, lbm->lbm_buckets[ii]); ii, lbm->lbm_buckets[ii]);
} }
load_balance_map_unlock(lbmi);
/* /*
* tidy up * tidy up
@ -3718,6 +3722,10 @@ fib_test_v4 (void)
fib_entry_pool_size()); fib_entry_pool_size());
FIB_TEST((ENBR-5 == pool_elts(fib_urpf_list_pool)), "uRPF pool size is %d", FIB_TEST((ENBR-5 == pool_elts(fib_urpf_list_pool)), "uRPF pool size is %d",
pool_elts(fib_urpf_list_pool)); pool_elts(fib_urpf_list_pool));
FIB_TEST((0 == pool_elts(load_balance_map_pool)), "LB-map pool size is %d",
pool_elts(load_balance_map_pool));
FIB_TEST((lb_count == pool_elts(load_balance_pool)), "LB pool size is %d",
pool_elts(load_balance_pool));
return 0; return 0;
} }