diff options
author | Angelo Mantellini <manangel@cisco.com> | 2019-12-15 22:50:11 +0100 |
---|---|---|
committer | Angelo Mantellini <angelo.mantellini@cisco.com> | 2019-12-15 22:08:42 +0000 |
commit | a6325a7343cc971cfca45fb50e4d7a9b9b5a2982 (patch) | |
tree | fe846bdb9c24065f762ace775a3a2a1701f71afe /hicn-light | |
parent | 1439c2bc8a95e4b72dad45aafe4c1f7a581bcd5a (diff) |
[HICN-460] Check of parchashmap before creating iterator
Change-Id: I559e86e269026be601a5735f77bbcfac40f24694
Signed-off-by: Angelo Mantellini <angelo.mantellini@cisco.com>
Diffstat (limited to 'hicn-light')
-rw-r--r-- | hicn-light/src/hicn/core/mapme.c | 34 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/loadBalancer.c | 29 |
2 files changed, 33 insertions, 30 deletions
diff --git a/hicn-light/src/hicn/core/mapme.c b/hicn-light/src/hicn/core/mapme.c index af332ede2..a0a34e8ce 100644 --- a/hicn-light/src/hicn/core/mapme.c +++ b/hicn-light/src/hicn/core/mapme.c @@ -351,28 +351,30 @@ static bool mapme_setFacePending(const MapMe *mapme, const Name *name, * It is likely we cannot iterator and remove elements from the hashmap at * the same time, so we proceed in two steps */ - NumberSet * conns = numberSet_Create(); + if (parcHashMap_Size(TFIB(fibEntry)->nexthops) > 0) { - PARCIterator *it = parcHashMap_CreateKeyIterator(TFIB(fibEntry)->nexthops); - while (parcIterator_HasNext(it)) { - PARCUnsigned *cid = parcIterator_Next(it); - unsigned conn_id = parcUnsigned_GetUnsigned(cid); - numberSet_Add(conns, conn_id); - } - parcIterator_Release(&it); + NumberSet * conns = numberSet_Create(); + + PARCIterator *it = parcHashMap_CreateKeyIterator(TFIB(fibEntry)->nexthops); + while (parcIterator_HasNext(it)) { + PARCUnsigned *cid = parcIterator_Next(it); + unsigned conn_id = parcUnsigned_GetUnsigned(cid); + numberSet_Add(conns, conn_id); + } + parcIterator_Release(&it); - for (size_t i = 0; i < numberSet_Length(conns); i++) { - unsigned conn_id = numberSet_GetItem(conns, i); - PARCEventTimer *oldTimer = (PARCEventTimer *)mapmeTFIB_Get(TFIB(fibEntry), conn_id); - if (oldTimer) + for (size_t i = 0; i < numberSet_Length(conns); i++) { + unsigned conn_id = numberSet_GetItem(conns, i); + PARCEventTimer *oldTimer = (PARCEventTimer *)mapmeTFIB_Get(TFIB(fibEntry), conn_id); + if (oldTimer) parcEventTimer_Stop(oldTimer); - mapmeTFIB_Remove(TFIB(fibEntry), conn_id); - } + mapmeTFIB_Remove(TFIB(fibEntry), conn_id); + } - numberSet_Release(&conns); + numberSet_Release(&conns); + } } - // NOTE // - at producer, send always true, we always send something reliably so we // set the timer. diff --git a/hicn-light/src/hicn/strategies/loadBalancer.c b/hicn-light/src/hicn/strategies/loadBalancer.c index e3f377791..35d64e763 100644 --- a/hicn-light/src/hicn/strategies/loadBalancer.c +++ b/hicn-light/src/hicn/strategies/loadBalancer.c @@ -344,22 +344,23 @@ static void _strategyLoadBalancer_ImplDestroy(StrategyImpl **strategyPtr) { StrategyImpl *impl = *strategyPtr; StrategyLoadBalancer *strategy = (StrategyLoadBalancer *)impl->context; + if (parcHashMap_Size(strategy->strategy_state) > 0) { + PARCIterator *it = parcHashMap_CreateKeyIterator(strategy->strategy_state); + while (parcIterator_HasNext(it)) { + PARCUnsigned *cid = parcIterator_Next(it); + StrategyNexthopState *state = + (StrategyNexthopState *) parcHashMap_Get(strategy->strategy_state, cid); + parcObject_Release((void **) &state); + } + parcIterator_Release(&it); - PARCIterator *it = parcHashMap_CreateKeyIterator(strategy->strategy_state); - while (parcIterator_HasNext(it)) { - PARCUnsigned *cid = parcIterator_Next(it); - StrategyNexthopState *state = - (StrategyNexthopState *)parcHashMap_Get(strategy->strategy_state, cid); - parcObject_Release((void**)&state); - } - parcIterator_Release(&it); - - parcHashMap_Release(&(strategy->strategy_state)); + parcHashMap_Release(&(strategy->strategy_state)); #ifndef WITH_POLICY - numberSet_Release(&(strategy->nexthops)); + numberSet_Release(&(strategy->nexthops)); #endif /* ! WITH_POLICY */ - parcMemory_Deallocate((void **)&strategy); - parcMemory_Deallocate((void **)&impl); - *strategyPtr = NULL; + parcMemory_Deallocate((void **) &strategy); + parcMemory_Deallocate((void **) &impl); + *strategyPtr = NULL; + } } |