void purge_shp_hash(time_t secs_now) { struct hashtable_itr *iterator=NULL; shpinfo *si; int ret; if (secs_now > purge_time) { // Time to purge //time_now = localtime(&secs_now); //(void)strftime(timestring,100,"%a %b %d %H:%M:%S %Z %Y",time_now); //fprintf(stderr,"Purging...%s\n",timestring); purge_time += PURGE_PERIOD; if (shp_hash) { // walk through the hash table and kill entries that are old iterator=hashtable_iterator(shp_hash); do { ret=0; if (iterator) { // must check this, because could be null // if the iterator malloc failed si=hashtable_iterator_value(iterator); if (si) { if (secs_now > si->last_access+PURGE_PERIOD) { // this is stale, hasn't been accessed in a while //fprintf(stderr, // "found stale entry for %s, deleting it.\n", // si->filename); //fprintf(stderr," Destroying si=%lx\n", // (unsigned long int) si); ret=hashtable_iterator_remove(iterator); // Important that we NOT do the // destroy first, because we've used // the filename pointer field of the // structure as the key, and the // remove function will free that. If // we clobber the struct first, we // invite segfaults destroy_shpinfo(si); //fprintf(stderr," removing from hashtable\n"); } else { ret=hashtable_iterator_advance(iterator); } } } } while (ret); // we're now done with the iterator. Free it to stop us from // leaking! if (iterator) free(iterator); } //fprintf(stderr," done Purging...\n"); } }
void symbols_close(void) { if(hashtable_count(symbol_table)) { struct hashtable_itr *itr = hashtable_iterator(symbol_table); do { struct symbol *s = hashtable_iterator_value(itr); free((void *) s->decl); free(s); } while(hashtable_iterator_remove(itr)); free(itr); } hashtable_destroy(symbol_table, 0); }
static void do_clean_hashtable(zk_hashtable* ht) { struct hashtable_itr *it; int hasMore; if(hashtable_count(ht->ht)==0) return; it=hashtable_iterator(ht->ht); do { watcher_object_list_t* w=hashtable_iterator_value(it); destroy_watcher_object_list(w); hasMore=hashtable_iterator_remove(it); } while(hasMore); free(it); }
void reclose_cache(void) { struct reformat *re; struct hashtable_itr *itr; char *filesname; #ifdef DEBUG_TIME struct timeval start_time, end_time; gettimeofday(&start_time, NULL); #endif //itererer over hash, frigjør alle elementer if (lots_cache!= NULL && hashtable_count(lots_cache) > 0) { itr = hashtable_iterator(lots_cache); do { filesname = hashtable_iterator_key(itr); re = hashtable_iterator_value(itr); #ifdef DEBUG printf("reclose_cache: closing \"%s\"\n",filesname); #endif if (re != NULL) { reclose(re); } } while (hashtable_iterator_remove(itr)); free(itr); } #ifdef DEBUG_TIME gettimeofday(&end_time, NULL); printf("Time debug: reclose_cache %f\n",getTimeDifference(&start_time,&end_time)); #endif return; }
cinv_status_t cinv_structure_delete(CInvContext *context, CInvStructure *structure) { if (hashtable_count(structure->members) > 0) { struct hashtable_itr it; hashtable_iterator(structure->members, &it); do { free(hashtable_iterator_key(&it)); free(hashtable_iterator_value(&it)); } while (hashtable_iterator_remove(&it)); } hashtable_destroy(structure->members, 0); free(structure); context_clear_error(context); return CINV_SUCCESS; }
static void __dsui_cleanup() { int i; hashtable_itr_t itr; dprintf("called\n"); for(i=0; i < MAX_DS; i++) { __dsui_close_datastream(i); } if (!hashtable_count(logging_threads)) { return; } init_iterator(&itr, logging_threads); do { struct logging_thread *log; log = hashtable_iterator_value(&itr); close_logging_thread(log); free(log); } while (hashtable_iterator_remove(&itr)); }
/** * Clean policy table, remove all UNVERIFIED filters and routes. * Anything left in the UNVERIFIED state (status) will be deleted. */ void policy_table_clean(void) { policy_table_entry_t * policy = NULL; ped_policy_route_t * route_tmp = NULL, * route = NULL; struct hashtable_itr * iterator = NULL; if(hashtable_count(if_table) < 1 || !clean_table || !get_ssd_ready() || !get_ssd_idle()) { return; // nothing to do or don't clean yet } junos_trace(PED_TRACEFLAG_HT, "%s", __func__); iterator = hashtable_iterator(if_table); // mallocs INSIST(iterator != NULL); // go through all policies do { policy = hashtable_iterator_value(iterator); // if we have a broken policy, then remove it if(policy->broken) { // remove and delete filters if(policy->filter) { remove_filters_from_interface(policy->ifname); free(policy->filter); } if(policy->pfd_filter) { remove_pfd_filter_from_interface(policy->ifname); policy->pfd_filter = FALSE; } // remove and delete routes route = policy->route; while(route) { route_tmp = route; // Save pointer to current route. route = route->next; // Move to the next route. if(route_tmp->status != ROUTE_FAILED) { remove_route(route_tmp); if(route->status == ROUTE_PENDING) { --changes_pending; } } free(route_tmp); // Free the current route data. } free(policy); if(hashtable_iterator_remove(iterator)) continue; else break; } // else: policy is not broken // but we will check for routes or filters that don't belong // Check filter: if(policy->filter && policy->filter->status == FILTER_UNVERIFIED) { free(policy->filter); policy->filter = NULL; remove_filters_from_interface(policy->ifname); } if(!policy->pfd_filter) { policy->pfd_filter = apply_pfd_filter_to_interface(policy->ifname); } // Check route(s): route = policy->route; route_tmp = NULL; policy->route = NULL; // Detach route list temporarily while(route) { // check we don't get FAILED routes (in non-broken policies) if(route->status == ROUTE_FAILED) { // log and crash because this shouldn't happen ERRMSG(PED, TRACE_LOG_EMERG, "%s: Found a route with status=FAILED in a non-broken " "policy. This should not happen.", __func__); // abort() is called in the above ERRMSG } // its status should probably be ADDED... // unless it's not part of the PSD policy anymore it will be: // UNVERIFIED if(route->status == ROUTE_UNVERIFIED) { // we've received all routes from the PSD, so it is // no longer part of the policy, and we need to delete it // copy route data into new mem to pass to callback // we choose to do this only when policy is not broken if(route_tmp) { // route_tmp points to last kept route route_tmp->next = route->next; remove_route(route); free(route); // make route point to the next route (in tmp->next) and route = route_tmp->next; } else { // No previous routes that we've kept yet // use tmp ptr to save next route_tmp = route->next; remove_route(route); free(route); // restore route to next route (in tmp) and tmp to NULL route = route_tmp; route_tmp = NULL; } } else { // a route we are keeping if(policy->route == NULL) { policy->route = route; // First route in the new list } route_tmp = route; // move route_tmp to end route = route->next; } } // Done checking route(s) } while (hashtable_iterator_advance(iterator)); free(iterator); clean_table = FALSE; }