/* * appTeardown() * * Teardown all modules, close all files, and tidy up all * application state. * * This function is idempotent. */ static void appTeardown( void) { static int teardownFlag = 0; RBLIST *iter; transfer_t *sndr; if (teardownFlag) { return; } teardownFlag = 1; if (!daemonized) { rbdestroy(transfers); skDLListDestroy(duplicate_dirs); skDLListDestroy(open_file_list); skdaemonTeardown(); skAppUnregister(); return; } NOTICEMSG("Begin shutting down..."); shuttingdown = 1; transferShutdown(); transferTeardown(); /* Destroy stuff */ iter = rbopenlist(transfers); CHECK_ALLOC(iter); while ((sndr = (transfer_t *)rbreadlist(iter)) != NULL) { if (sndr->ident != NULL) { free(sndr->ident); } if (sndr->addr) { skSockaddrArrayDestroy(sndr->addr); } free(sndr); } rbcloselist(iter); rbdestroy(transfers); skDLListDestroy(duplicate_dirs); skDLListDestroy(open_file_list); NOTICEMSG("Finished shutting down."); skdaemonTeardown(); skthread_teardown(); skAppUnregister(); }
void sudo_freepwcache(void) { if (pwcache_byuid != NULL) { rbdestroy(pwcache_byuid, pw_delref_item); pwcache_byuid = NULL; } if (pwcache_byname != NULL) { rbdestroy(pwcache_byname, pw_delref_item); pwcache_byname = NULL; } }
void sudo_freegrcache(void) { if (grcache_bygid != NULL) { rbdestroy(grcache_bygid, gr_delref_item); grcache_bygid = NULL; } if (grcache_byname != NULL) { rbdestroy(grcache_byname, gr_delref_item); grcache_byname = NULL; } }
void skPDUSourceDestroy( skPDUSource_t *source) { RBLIST *iter; pdu_engine_info_t *engine_info; if (!source) { return; } if (!source->stopped) { skPDUSourceStop(source); } skUDPSourceDestroy(source->source); pthread_mutex_destroy(&source->stats_mutex); iter = rbopenlist(source->engine_info_tree); if (iter != NULL) { while ((engine_info = (pdu_engine_info_t *)rbreadlist(iter))) { free(engine_info); } rbcloselist(iter); } rbdestroy(source->engine_info_tree); free(source); }
static void RB_Purge (const struct rbtree *r) { RBLIST *rblist; const void *val; void *data; void *ptr; if ((rblist=rbopenlist(rb)) != NULL) { while((val=rbreadlist(rblist)) != NULL) { data = rbfind (val, rb); ptr = *(void **)data; rbdelete (val, rb); if (ptr) Z_Free (ptr); } } rbcloselist(rblist); rbdestroy (rb); FS_InitCache(); }
/* ================ FS_SetGamedir Sets the gamedir and path to a different directory. ================ */ void FS_SetGamedir (const char *dir) { searchpath_t *next; if (strstr(dir, "..") || strchr(dir, '/') || strchr(dir, '\\') || strchr(dir, ':') ) { Com_Printf ("Gamedir '%s' should be a single filename, not a path\n", LOG_GENERAL, dir); return; } // // free up any current game dir info // while (fs_searchpaths != fs_base_searchpaths) { if (fs_searchpaths->pack) { fclose (fs_searchpaths->pack->h.handle); //Z_Free (fs_searchpaths->pack->files); rbdestroy (fs_searchpaths->pack->rb); Z_Free (fs_searchpaths->pack); } next = fs_searchpaths->next; Z_Free (fs_searchpaths); fs_searchpaths = next; } // // flush all data, so it will be forced to reload // FS_FlushCache(); #ifndef DEDICATED_ONLY #ifndef NO_SERVER if (!dedicated->intvalue) { #endif //Cbuf_AddText ("vid_restart\nsnd_restart\n"); Cmd_ExecuteString ("vid_restart"); Cmd_ExecuteString ("snd_restart"); #ifndef NO_SERVER } #endif #endif if (!strcmp(dir,BASEDIRNAME) || (*dir == 0)) { Com_sprintf (fs_gamedir, sizeof(fs_gamedir), "%s/%s", fs_basedir->string, BASEDIRNAME); Cvar_FullSet ("gamedir", "", CVAR_SERVERINFO|CVAR_NOSET); Cvar_FullSet ("game", "", CVAR_LATCH|CVAR_SERVERINFO); } else { Com_sprintf (fs_gamedir, sizeof(fs_gamedir), "%s/%s", fs_basedir->string, dir); Cvar_FullSet ("gamedir", dir, CVAR_SERVERINFO|CVAR_NOSET); FS_AddGameDirectory (va("%s/%s", fs_basedir->string, dir) ); } }
void FS_ReloadPAKs (void) { const char *dir; searchpath_t *next; // // free up any current game dir info // while (fs_searchpaths != fs_base_searchpaths) { if (fs_searchpaths->pack) { fclose (fs_searchpaths->pack->h.handle); //Z_Free (fs_searchpaths->pack->files); //RB_Purge (fs_searchpaths->pack->rb); rbdestroy (fs_searchpaths->pack->rb); Z_Free (fs_searchpaths->pack); } next = fs_searchpaths->next; Z_Free (fs_searchpaths); fs_searchpaths = next; } dir = Cvar_VariableString ("gamedir"); if (dir[0] && strcmp(dir, BASEDIRNAME)) FS_AddGameDirectory (va("%s/%s", fs_basedir->string, dir) ); }
int main() { int i, *ptr; const void *val; struct rbtree *rb; srand(getpid()); if ((rb=rbinit(compare, NULL))==NULL) { fprintf(stderr, "insufficient memory\n"); exit(1); } for (i = 0; i < 12; i++) { ptr = (int *)xmalloc(sizeof(int)); *ptr = rand()&0xff; val = rbsearch((void *)ptr, rb); if(val == NULL) { fprintf(stderr, "insufficient memory\n"); exit(1); } } for(val=rblookup(RB_LUFIRST, NULL, rb); val!=NULL; val=rblookup(RB_LUNEXT, val, rb)) { printf("%6d\n", *(int *)val); } rbdestroy(rb); return 0; }
void stasis_aggregate_min_deinit(stasis_aggregate_min_t * min) { if(min->tree) { rbdestroy(min->tree); } else { } free(min->vals); pthread_key_delete(min->key); free(min); }
int main(int argc, char** argv) { ITEM *ptr, *result; struct rbtree *rb; ITEM c; FILE *f; char *dbName = "f_inc.0.u.test"; c.w = atof(argv[1]); c.value = -1; if ((rb=rbinit(compare, NULL))==NULL) { fprintf(stderr, "insufficient memory\n"); exit(1); } f = fopen(dbName, "r"); ptr = (ITEM *)xmalloc(sizeof(ITEM)); while (fscanf(f, "%lf", &ptr->w) != EOF) { fscanf(f, "%lf", &ptr->value); rbsearch(ptr, rb); ptr = (ITEM *)xmalloc(sizeof(ITEM)); } result = (ITEM *)rbsearch(&c, rb); fprintf(stdout, "%.8lf\t%.8lf\n", result->w, result->value); /* for (i = 50000; i > 0; i--) { ptr = (ITEM *)xmalloc(sizeof(ITEM)); ptr->w = i; ptr->value = (double)i/7; val = rbsearch((void *)ptr, rb); if(val == NULL) { fprintf(stderr, "insufficient memory\n"); exit(1); } } rbwalk(rb, walkact, "No"); printf("Minimum branch length: %d\n", minleaf); printf("Maximum branch length: %d\n", maxleaf); */ rbdestroy(rb); return 0; }
void upnp_entry_free (struct ushare_t *ut, struct upnp_entry_t *entry) { if (!ut || !entry) return; /* Free all entries (i.e. children) */ if (entry == ut->root_entry) { struct upnp_entry_t *entry_found = NULL; struct upnp_entry_lookup_t *lk = NULL; RBLIST *rblist; int i = 0; rblist = rbopenlist (ut->rb); lk = (struct upnp_entry_lookup_t *) rbreadlist (rblist); while (lk) { entry_found = lk->entry_ptr; if (entry_found) { if (entry_found->fullpath) free (entry_found->fullpath); if (entry_found->title) free (entry_found->title); if (entry_found->url) free (entry_found->url); free (entry_found); i++; } free (lk); /* delete the lookup */ lk = (struct upnp_entry_lookup_t *) rbreadlist (rblist); } rbcloselist (rblist); rbdestroy (ut->rb); ut->rb = NULL; log_verbose ("Freed [%d] entries\n", i); } else _upnp_entry_free (entry); free (entry); }
void int_dict_destroy( int_dict_t *dict) { assert(dict); assert(dict->tree); WRITE_LOCK(&dict->mutex); rbwalk(dict->tree, destroy_node, NULL); rbdestroy(dict->tree); if (dict->tnode != NULL) { free(dict->tnode); } RW_MUTEX_UNLOCK(&dict->mutex); RW_MUTEX_DESTROY(&dict->mutex); free(dict); }
void Cvar_Quit(void) { rbdestroy(cvartree); cvartree = NULL; cvar_t *var = cvar_vars; while (var) { cvar_t *next = var->next; var->next = NULL; Z_Free(var->name); var->name = NULL; Z_Free(var->string); var->string = NULL; Z_Free(var); var = next; } cvar_vars = NULL; }
void free_metadata_list (struct ushare_t *ut) { ut->init = 0; if (ut->root_entry) upnp_entry_free (ut, ut->root_entry); ut->root_entry = NULL; ut->nr_entries = 0; if (ut->rb) { rbdestroy (ut->rb); ut->rb = NULL; } ut->rb = rbinit (rb_compare, NULL); if (!ut->rb) log_error (_("Cannot create RB tree for lookups\n")); }
skPDUSource_t * skPDUSourceCreate( const skpc_probe_t *probe, const skFlowSourceParams_t *params) { skPDUSource_t *source; assert(probe); /* Create and initialize source */ source = (skPDUSource_t*)calloc(1, sizeof(*source)); if (source == NULL) { goto ERROR; } source->probe = probe; source->name = skpcProbeGetName(probe); source->logopt = skpcProbeGetLogFlags(probe); source->engine_info_tree = rbinit(pdu_engine_compare, NULL); if (source->engine_info_tree == NULL) { goto ERROR; } source->source = skUDPSourceCreate(probe, params, V5PDU_LEN, &pduSourceRejectPacket, source); if (NULL == source->source) { goto ERROR; } pthread_mutex_init(&source->stats_mutex, NULL); return source; ERROR: if (source) { if (source->engine_info_tree) { rbdestroy(source->engine_info_tree); } free(source); } return NULL; }
int main() { int i, *ptr; const void *val; struct rbtree *rb; RBLIST *rblist; if ((rb=rbinit(compare, NULL))==NULL) { fprintf(stderr, "insufficient memory from rbinit()\n"); exit(1); } for (i = 200; i > 0; i--) { ptr = (int *)xmalloc(sizeof(int)); *ptr = i; val = rbsearch((void *)ptr, rb); if(val == NULL) { fprintf(stderr, "insufficient memory from rbsearch()\n"); exit(1); } } if ((rblist=rbopenlist(rb))==NULL) { fprintf(stderr, "insufficient memory from rbopenlist()\n"); exit(1); } while((val=rbreadlist(rblist))) { printf("%6d\n", *(int *)val); } rbcloselist(rblist); rbdestroy(rb); return 0; }
/** * scan an iTunes xml music database file, augmenting * the metainfo with that found in the xml file * * @param filename xml file to parse * @returns TRUE if playlist parsed successfully, FALSE otherwise */ int scan_xml_playlist(char *filename) { char *working_base; const void *val; int retval=TRUE; SCAN_XML_RB *lookup_ptr; SCAN_XML_RB lookup_val; RXMLHANDLE xml_handle; MAYBEFREE(scan_xml_itunes_version); MAYBEFREE(scan_xml_itunes_base_path); MAYBEFREE(scan_xml_itunes_decoded_base_path); MAYBEFREE(scan_xml_real_base_path); scan_xml_file = filename; /* initialize the redblack tree */ if((scan_xml_db = rbinit(scan_xml_rb_compare,NULL)) == NULL) { DPRINTF(E_LOG,L_SCAN,"Could not initialize red/black tree\n"); return FALSE; } /* find the base dir of the itunes playlist itself */ working_base = strdup(filename); if(strrchr(working_base,'/')) { *(strrchr(working_base,'/') + 1) = '\x0'; scan_xml_real_base_path = strdup(working_base); } else { scan_xml_real_base_path = strdup("/"); } free(working_base); DPRINTF(E_SPAM,L_SCAN,"Parsing xml file: %s\n",filename); if(!rxml_open(&xml_handle,filename,scan_xml_handler,NULL)) { DPRINTF(E_LOG,L_SCAN,"Error opening xml file %s: %s\n", filename,rxml_errorstring(xml_handle)); } else { if(!rxml_parse(xml_handle)) { retval=FALSE; DPRINTF(E_LOG,L_SCAN,"Error parsing xml file %s: %s\n", filename,rxml_errorstring(xml_handle)); } } rxml_close(xml_handle); /* destroy the redblack tree */ val = rblookup(RB_LUFIRST,NULL,scan_xml_db); while(val) { lookup_val.itunes_index = ((SCAN_XML_RB*)val)->itunes_index; lookup_ptr = (SCAN_XML_RB *)rbdelete((void*)&lookup_val,scan_xml_db); if(lookup_ptr) free(lookup_ptr); val = rblookup(RB_LUFIRST,NULL,scan_xml_db); } rbdestroy(scan_xml_db); MAYBEFREE(scan_xml_itunes_version); MAYBEFREE(scan_xml_itunes_base_path); MAYBEFREE(scan_xml_itunes_decoded_base_path); MAYBEFREE(scan_xml_real_base_path); return retval; }
int print_info() { unsigned int num_watches = 0; num_watches = inotifytools_get_num_watches(); if ( !inotifytools_get_stat_total( 0 ) ) { fprintf( stderr, "No events occurred.\n" ); return EXIT_SUCCESS; } // OK, go through the watches and print stats. printf("total "); if ( (IN_ACCESS & events) && ( zero || inotifytools_get_stat_total( IN_ACCESS ) ) ) printf("access "); if ( ( IN_MODIFY & events) && ( zero || inotifytools_get_stat_total( IN_MODIFY ) ) ) printf("modify "); if ( ( IN_ATTRIB & events) && ( zero || inotifytools_get_stat_total( IN_ATTRIB ) ) ) printf("attrib "); if ( ( IN_CLOSE_WRITE & events) && ( zero || inotifytools_get_stat_total( IN_CLOSE_WRITE ) ) ) printf("close_write "); if ( ( IN_CLOSE_NOWRITE & events) && ( zero || inotifytools_get_stat_total( IN_CLOSE_NOWRITE ) ) ) printf("close_nowrite "); if ( ( IN_OPEN & events) && ( zero || inotifytools_get_stat_total( IN_OPEN ) ) ) printf("open "); if ( ( IN_MOVED_FROM & events) && ( zero || inotifytools_get_stat_total( IN_MOVED_FROM ) ) ) printf("moved_from "); if ( ( IN_MOVED_TO & events) && ( zero || inotifytools_get_stat_total( IN_MOVED_TO ) ) ) printf("moved_to "); if ( ( IN_MOVE_SELF & events) && ( zero || inotifytools_get_stat_total( IN_MOVE_SELF ) ) ) printf("move_self "); if ( ( IN_CREATE & events) && ( zero || inotifytools_get_stat_total( IN_CREATE ) ) ) printf("create "); if ( ( IN_DELETE & events) && ( zero || inotifytools_get_stat_total( IN_DELETE ) ) ) printf("delete "); if ( ( IN_DELETE_SELF & events) && ( zero || inotifytools_get_stat_total( IN_DELETE_SELF ) ) ) printf("delete_self "); if ( ( IN_UNMOUNT & events) && ( zero || inotifytools_get_stat_total( IN_UNMOUNT ) ) ) printf("unmount "); printf("filename\n"); struct rbtree *tree = inotifytools_wd_sorted_by_event(sort); RBLIST *rblist = rbopenlist(tree); watch *w = (watch*)rbreadlist(rblist); while (w) { if ( !zero && !w->hit_total ) { w = (watch*)rbreadlist(rblist); continue; } printf("%-5u ", w->hit_total ); if ( ( IN_ACCESS & events) && ( zero || inotifytools_get_stat_total( IN_ACCESS ) ) ) printf("%-6u ", w->hit_access ); if ( ( IN_MODIFY & events) && ( zero || inotifytools_get_stat_total( IN_MODIFY ) ) ) printf("%-6u ", w->hit_modify ); if ( ( IN_ATTRIB & events) && ( zero || inotifytools_get_stat_total( IN_ATTRIB ) ) ) printf("%-6u ", w->hit_attrib ); if ( ( IN_CLOSE_WRITE & events) && ( zero || inotifytools_get_stat_total( IN_CLOSE_WRITE ) ) ) printf("%-11u ",w->hit_close_write ); if ( ( IN_CLOSE_NOWRITE & events) && ( zero || inotifytools_get_stat_total( IN_CLOSE_NOWRITE ) ) ) printf("%-13u ",w->hit_close_nowrite ); if ( ( IN_OPEN & events) && ( zero || inotifytools_get_stat_total( IN_OPEN ) ) ) printf("%-4u ", w->hit_open ); if ( ( IN_MOVED_FROM & events) && ( zero || inotifytools_get_stat_total( IN_MOVED_FROM ) ) ) printf("%-10u ", w->hit_moved_from ); if ( ( IN_MOVED_TO & events) && ( zero || inotifytools_get_stat_total( IN_MOVED_TO ) ) ) printf("%-8u ", w->hit_moved_to ); if ( ( IN_MOVE_SELF & events) && ( zero || inotifytools_get_stat_total( IN_MOVE_SELF ) ) ) printf("%-9u ", w->hit_move_self ); if ( ( IN_CREATE & events) && ( zero || inotifytools_get_stat_total( IN_CREATE ) ) ) printf("%-6u ", w->hit_create ); if ( ( IN_DELETE & events) && ( zero || inotifytools_get_stat_total( IN_DELETE ) ) ) printf("%-6u ", w->hit_delete ); if ( ( IN_DELETE_SELF & events) && ( zero || inotifytools_get_stat_total( IN_DELETE_SELF ) ) ) printf("%-11u ",w->hit_delete_self ); if ( ( IN_UNMOUNT & events) && ( zero || inotifytools_get_stat_total( IN_UNMOUNT ) ) ) printf("%-7u ", w->hit_unmount ); printf("%s\n", w->filename ); w = (watch*)rbreadlist(rblist); } rbcloselist(rblist); rbdestroy(tree); return EXIT_SUCCESS; }
void connect_destroy(void) { rbdestroy(state_tbl); }