for (int i = 0; i < fibEntryList_Length(list); i++) {
_removeNode(fib, fibEntry_GetPrefix(fibEntryList_Get(list, i)));
}
+
+ fibEntryList_Destroy(&list);
}
size_t fib_Length(const FIB *fib) {
fibEntry_GetAvailableNextHops(const FibEntry *fibEntry, unsigned in_connection) {
ConnectionTable * table = forwarder_GetConnectionTable(fibEntry->forwarder);
NumberSet * nexthops;
+ bool dealloc_nexthops = false;
policy_t policy = fibEntry_GetPolicy(fibEntry);
/* Reset available next hops and start filtering */
if (in_connection == ~0) {
/* We might advertise among all available up connections */
nexthops = numberSet_Create();
+ dealloc_nexthops = true;
ConnectionList * list = connectionTable_GetEntries(table);
for (size_t i = 0; i < connectionList_Length(list); i++) {
continue;
numberSet_Add(nexthops, connection_GetConnectionId(conn));
}
-
+ connectionList_Destroy(&list);
} else {
nexthops = (NumberSet*)fibEntry_GetNexthops(fibEntry);
for (size_t k = 0; k < numberSet_Length(nexthops); k++) {
numberSet_Add(available_nexthops, conn_id);
}
- if (numberSet_Length(available_nexthops) > 0)
+ if (numberSet_Length(available_nexthops) > 0){
+ if(dealloc_nexthops){
+ numberSet_Release(&nexthops);
+ }
return available_nexthops;
+ }
}
for (size_t k = 0; k < numberSet_Length(nexthops); k++) {
numberSet_Add(available_nexthops, conn_id);
}
+ if(dealloc_nexthops)
+ numberSet_Release(&nexthops);
+
if (numberSet_Length(available_nexthops) == 0)
return available_nexthops;
unsigned ifidx) {
Configuration *config = forwarder_GetConfiguration(processor->forwarder);
- const char *prefixStr = utils_PrefixLenToString(
+ char *prefixStr = (char *) utils_PrefixLenToString(
control->addressType, &control->address, &control->len);
strategy_type fwdStrategy =
configuration_GetForwardingStrategy(config, prefixStr);
fib_Add(processor->fib, entry);
}
+ free(prefixStr);
name_Release(&prefix);
/* For policy implementation, we need access to the ConnectionTable in all
PARCUnsigned *cid = parcUnsigned_Create(numberSet_GetItem(nexthops, i));
const StrategyNexthopState *elem =
parcHashMap_Get(lb->strategy_state, cid);
+ parcUnsigned_Release(&cid);
if (!elem)
continue;
sum += strategyNexthopState_GetWeight(elem);
PARCUnsigned *cid = parcUnsigned_Create(numberSet_GetItem(nexthops, i));
const StrategyNexthopState *state =
parcHashMap_Get(lb->strategy_state, cid);
- if (!state)
- continue;
+ if (!state){
+ parcUnsigned_Release(&cid);
+ continue;
+ }
distance -= strategyNexthopState_GetWeight(state);
if (distance < 0) {
numberSet_Add(outList, parcUnsigned_GetUnsigned(cid));
_update_Stats(lb, (StrategyNexthopState *)state, true);
+ parcUnsigned_Release(&cid);
break;
}
}
static void _strategyLoadBalancer_AddNexthop(StrategyImpl *strategy,
unsigned connectionId) {
- StrategyNexthopState *state = strategyNexthopState_Create();
PARCUnsigned *cid = parcUnsigned_Create(connectionId);
StrategyLoadBalancer *lb = (StrategyLoadBalancer *)strategy->context;
if (!parcHashMap_Contains(lb->strategy_state, cid)) {
+ StrategyNexthopState *state = strategyNexthopState_Create();
parcHashMap_Put(lb->strategy_state, cid, state);
#ifndef WITH_POLICY
numberSet_Add(lb->nexthops, connectionId);
#endif /* WITH_POLICY */
_strategyLoadBalancer_resetState(strategy);
}
+ parcUnsigned_Release(&cid);
}
static void _strategyLoadBalancer_RemoveNexthop(StrategyImpl *strategy,