void test_avl_tree_free(void) { AVLTree *tree; /* Try freeing an empty tree */ tree = avl_tree_new((AVLTreeCompareFunc) int_compare); avl_tree_free(tree); /* Create a big tree and free it */ tree = create_tree(); avl_tree_free(tree); }
/* Remove the provided source from the global tree and free it */ void source_free_source (source_t *source) { DEBUG1 ("freeing source \"%s\"", source->mount); avl_tree_wlock (global.source_tree); avl_delete (global.source_tree, source, NULL); avl_tree_unlock (global.source_tree); avl_tree_free(source->pending_tree, _free_client); avl_tree_free(source->client_tree, _free_client); free (source->mount); free (source); return; }
void fserve_shutdown(void) { if (!__inited) return; thread_spin_lock (&pending_lock); run_fserv = 0; while (pending_list) { fserve_t *to_go = (fserve_t *)pending_list; pending_list = to_go->next; fserve_client_destroy (to_go); } while (active_list) { fserve_t *to_go = active_list; active_list = to_go->next; fserve_client_destroy (to_go); } if (mimetypes) avl_tree_free (mimetypes, _delete_mapping); thread_spin_unlock (&pending_lock); thread_spin_destroy (&pending_lock); ICECAST_LOG_INFO("file serving stopped"); }
void test_avl_tree_lookup(void) { AVLTree *tree; int i; int *value; /* Create a tree and look up all values */ tree = create_tree(); for (i=0; i<NUM_TEST_VALUES; ++i) { value = avl_tree_lookup(tree, &i); assert(value != NULL); assert(*value == i); } /* Test invalid values */ i = -1; assert(avl_tree_lookup(tree, &i) == NULL); i = NUM_TEST_VALUES + 1; assert(avl_tree_lookup(tree, &i) == NULL); i = 8724897; assert(avl_tree_lookup(tree, &i) == NULL); avl_tree_free(tree); }
static int _delete_fh (void *mapping) { fh_node *fh = mapping; if (fh == &no_file) { ERROR0 ("no file handle free detected"); return 0; } if (fh->refcount) WARN2 ("handle for %s has refcount %d", fh->finfo.mount, fh->refcount); else thread_mutex_destroy (&fh->lock); file_close (&fh->f); if (fh->format) { free (fh->format->mount); format_plugin_clear (fh->format, NULL); free (fh->format); } if (fh->clients) avl_tree_free (fh->clients, NULL); rate_free (fh->out_bitrate); free (fh->finfo.mount); free (fh->finfo.fallback); free (fh); return 1; }
void connection_shutdown(void) { if (!_initialized) return; #ifdef HAVE_OPENSSL SSL_CTX_free (ssl_ctx); #endif if (banned_ip.contents) avl_tree_free (banned_ip.contents, free_filtered_ip); if (allowed_ip.contents) avl_tree_free (allowed_ip.contents, free_filtered_ip); thread_cond_destroy(&global.shutdown_cond); thread_rwlock_destroy(&_source_shutdown_rwlock); thread_spin_destroy (&_connection_lock); thread_mutex_destroy(&move_clients_mutex); _initialized = 0; }
static void htpasswd_clear(auth_t *self) { htpasswd_auth_state *state = self->state; free(state->filename); if (state->users) avl_tree_free (state->users, _free_user); thread_rwlock_destroy(&state->file_rwlock); free(state); }
/* Remove the provided source from the global tree and free it */ void source_free_source (source_t *source) { DEBUG1 ("freeing source \"%s\"", source->mount); avl_tree_wlock (global.source_tree); avl_delete (global.source_tree, source, NULL); avl_tree_unlock (global.source_tree); avl_tree_free(source->pending_tree, _free_client); avl_tree_free(source->client_tree, _free_client); /* make sure all YP entries have gone */ yp_remove (source->mount); free (source->mount); free (source); return; }
void init_trees(void) { if (competitors_tree) avl_tree_free(competitors_tree, free_avl_key); competitors_tree = avl_tree_new(competitors_avl_compare, NULL); avl_set_data(0, "", "", ""); avl_set_data(1000, "", "", ""); }
static int _free_source_stats(void *key) { stats_source_t *node = (stats_source_t *)key; avl_tree_free(node->stats_tree, _free_stats); free(node->source); free(node); return 1; }
void stats_shutdown() { int n; stats_event_t *event, *next; if(!_stats_running) /* We can't shutdown if we're not running. */ return; /* wait for thread to exit */ _stats_running = 0; thread_join(_stats_thread_id); /* wait for other threads to shut down */ do { thread_sleep(300000); thread_mutex_lock(&_stats_mutex); n = _stats_threads; thread_mutex_unlock(&_stats_mutex); } while (n > 0); /* free the queues */ /* destroy the queue mutexes */ thread_mutex_destroy(&_global_event_mutex); /* tear it all down */ thread_cond_destroy(&_event_signal_cond); thread_mutex_destroy(&_stats_mutex); avl_tree_free(_stats.source_tree, _free_source_stats); avl_tree_free(_stats.global_tree, _free_stats); event = _global_event_queue; while(event) { if(event->source) free(event->source); if(event->value) free(event->value); if(event->name) free(event->name); next = event->next; free(event); event = next; } }
void fserve_shutdown(void) { if(!run_fserv) return; run_fserv = 0; thread_join(fserv_thread); INFO0("file serving thread stopped"); avl_tree_free(mimetypes, _delete_mapping); }
void thread_shutdown(void) { if (_initialized == 1) { thread_mutex_destroy(&_library_mutex); thread_mutex_destroy(&_threadtree_mutex); #ifdef THREAD_DEBUG thread_mutex_destroy(&_mutextree_mutex); avl_tree_free(_mutextree, _free_mutex); #endif avl_tree_free(_threadtree, _free_thread); } #ifdef THREAD_DEBUG log_close(_logid); log_shutdown(); #endif }
void stats_shutdown(void) { int n; if (!_stats_running) /* We can't shutdown if we're not running. */ return; /* wait for thread to exit */ _stats_running = 0; thread_join(_stats_thread_id); /* wait for other threads to shut down */ do { thread_sleep(300000); thread_mutex_lock(&_stats_mutex); n = _stats_threads; thread_mutex_unlock(&_stats_mutex); } while (n > 0); ICECAST_LOG_INFO("stats thread finished"); /* free the queues */ /* destroy the queue mutexes */ thread_mutex_destroy(&_global_event_mutex); thread_mutex_destroy(&_stats_mutex); avl_tree_free(_stats.source_tree, _free_source_stats); avl_tree_free(_stats.global_tree, _free_stats); while (1) { stats_event_t *event = _get_event_from_queue (&_global_event_queue); if (event == NULL) break; if(event->source) free(event->source); if(event->value) free(event->value); if(event->name) free(event->name); free(event); } }
static int _free_source_stats(void *key) { stats_source_t *node = (stats_source_t *)key; stats_listener_send (node->flags, "DELETE %s\n", node->source); DEBUG1 ("delete source node %s", node->source); avl_tree_unlock (node->stats_tree); avl_tree_free(node->stats_tree, _free_stats); free(node->source); free(node); return 1; }
static void cache_prune (cache_file_contents *cache) { if (cache->contents) { avl_tree_free (cache->contents, cache_treenode_free); cache->contents = NULL; } while (cache->wildcards) { struct list_node *entry = cache->wildcards; cache->wildcards = entry->next; free (entry->content); free (entry); } }
void fserve_shutdown(void) { fserve_running = 0; if (mimetypes) avl_tree_free (mimetypes, _delete_mapping); if (fh_cache) { int count = 20; avl_delete (fh_cache, &no_file, NULL); while (fh_cache->length > 1 && count) { DEBUG1 ("waiting for %u entries to clear", fh_cache->length); thread_sleep (100000); count--; } avl_tree_free (fh_cache, _delete_fh); } thread_spin_destroy (&pending_lock); #ifndef HAVE_PREAD thread_mutex_destroy (&seekread_lock); #endif INFO0("file serving stopped"); }
void test_avl_tree_remove(void) { AVLTree *tree; int i; int x, y, z; int value; int expected_entries; tree = create_tree(); /* Try removing invalid entries */ i = NUM_TEST_VALUES + 100; assert(avl_tree_remove(tree, &i) == 0); i = -1; assert(avl_tree_remove(tree, &i) == 0); /* Delete the nodes from the tree */ expected_entries = NUM_TEST_VALUES; /* This looping arrangement causes nodes to be removed in a * randomish fashion from all over the tree. */ for (x=0; x<4; ++x) { for (y=0; y<4; ++y) { for (z=0; z<8; ++z) { value = z * 16 + (3 - y) * 4 + x; assert(avl_tree_remove(tree, &value) != 0); validate_tree(tree); expected_entries -= 1; assert(avl_tree_num_entries(tree) == expected_entries); } } } /* All entries removed, should be empty now */ assert(avl_tree_root_node(tree) == NULL); avl_tree_free(tree); }
void test_avl_tree_child(void) { AVLTree *tree; AVLTreeNode *root; AVLTreeNode *left; AVLTreeNode *right; int values[] = { 1, 2, 3 }; int *p; int i; /* Create a tree containing some values. Validate the * tree is consistent at all stages. */ tree = avl_tree_new((AVLTreeCompareFunc) int_compare); for (i=0; i<3; ++i) { avl_tree_insert(tree, &values[i], &values[i]); } /* Check the tree */ root = avl_tree_root_node(tree); p = avl_tree_node_value(root); assert(*p == 2); left = avl_tree_node_child(root, AVL_TREE_NODE_LEFT); p = avl_tree_node_value(left); assert(*p == 1); right = avl_tree_node_child(root, AVL_TREE_NODE_RIGHT); p = avl_tree_node_value(right); assert(*p == 3); /* Check invalid values */ assert(avl_tree_node_child(root, -1) == NULL); assert(avl_tree_node_child(root, 10000) == NULL); assert(avl_tree_node_child(root, 2) == NULL); assert(avl_tree_node_child(root, -100000) == NULL); avl_tree_free(tree); }
void test_avl_tree_insert_lookup(void) { AVLTree *tree; AVLTreeNode *node; int i; int *value; /* Create a tree containing some values. Validate the * tree is consistent at all stages. */ tree = avl_tree_new((AVLTreeCompareFunc) int_compare); for (i=0; i<NUM_TEST_VALUES; ++i) { test_array[i] = i; avl_tree_insert(tree, &test_array[i], &test_array[i]); assert(avl_tree_num_entries(tree) == i + 1); validate_tree(tree); } assert(avl_tree_root_node(tree) != NULL); /* Check that all values can be read back again */ for (i=0; i<NUM_TEST_VALUES; ++i) { node = avl_tree_lookup_node(tree, &i); assert(node != NULL); value = avl_tree_node_key(node); assert(*value == i); value = avl_tree_node_value(node); assert(*value == i); } /* Check that invalid nodes are not found */ i = -1; assert(avl_tree_lookup_node(tree, &i) == NULL); i = NUM_TEST_VALUES + 100; assert(avl_tree_lookup_node(tree, &i) == NULL); avl_tree_free(tree); }
static void test_avl_tree (void) { AVLTree* avl_tree; avl_tree = avl_tree_new (string_compare); avl_tree_free (avl_tree); }
~map_info() { avl_tree_free(m_tree, free_node); }
static void avl_tree_rdealloc( avl_tree_r* avl_tree ) { avl_tree_free( avl_tree->root ); free( avl_tree ); }
static void htpasswd_recheckfile (htpasswd_auth_state *htpasswd) { FILE *passwdfile; avl_tree *new_users; int num = 0; struct stat file_stat; char *sep; char line [MAX_LINE_LEN]; if (stat (htpasswd->filename, &file_stat) < 0) { WARN1 ("failed to check status of %s", htpasswd->filename); return; } if (file_stat.st_mtime == htpasswd->mtime) { /* common case, no update to file */ return; } INFO1 ("re-reading htpasswd file \"%s\"", htpasswd->filename); passwdfile = fopen (htpasswd->filename, "rb"); if (passwdfile == NULL) { WARN2("Failed to open authentication database \"%s\": %s", htpasswd->filename, strerror(errno)); return; } htpasswd->mtime = file_stat.st_mtime; new_users = avl_tree_new (compare_users, NULL); while (get_line(passwdfile, line, MAX_LINE_LEN)) { int len; htpasswd_user *entry; num++; if(!line[0] || line[0] == '#') continue; sep = strrchr (line, ':'); if (sep == NULL) { WARN2("No separator on line %d (%s)", num, htpasswd->filename); continue; } entry = calloc (1, sizeof (htpasswd_user)); len = strlen (line) + 1; entry->name = malloc (len); *sep = 0; memcpy (entry->name, line, len); entry->pass = entry->name + (sep-line) + 1; avl_insert (new_users, entry); } fclose (passwdfile); thread_rwlock_wlock (&htpasswd->file_rwlock); if (htpasswd->users) avl_tree_free (htpasswd->users, _free_user); htpasswd->users = new_users; thread_rwlock_unlock (&htpasswd->file_rwlock); }
void fserve_recheck_mime_types (ice_config_t *config) { mime_type *mapping; int i; avl_tree *old_mimetypes = NULL, *new_mimetypes = avl_tree_new(_compare_mappings, NULL); mime_type defaults[] = { { "m3u", "audio/x-mpegurl" }, { "pls", "audio/x-scpls" }, { "xspf", "application/xspf+xml" }, { "ogg", "application/ogg" }, { "mp3", "audio/mpeg" }, { "aac", "audio/aac" }, { "aacp", "audio/aacp" }, { "css", "text/css" }, { "txt", "text/plain" }, { "html", "text/html" }, { "jpg", "image/jpg" }, { "png", "image/png" }, { "gif", "image/gif" }, { NULL, NULL } }; for (i=0; defaults[i].ext; i++) { mapping = malloc (sizeof(mime_type)); mapping->ext = strdup (defaults [i].ext); mapping->type = strdup (defaults [i].type); if (avl_insert (new_mimetypes, mapping) != 0) _delete_mapping (mapping); } do { char *type, *ext, *cur; FILE *mimefile = NULL; char line[4096]; if (config->mimetypes_fn == NULL) { INFO0 ("no mime types file defined, using defaults"); break; } mimefile = fopen (config->mimetypes_fn, "r"); if (mimefile == NULL) { WARN1 ("Cannot open mime types file %s, using defaults", config->mimetypes_fn); break; } while (fgets(line, sizeof line, mimefile)) { line[4095] = 0; if(*line == 0 || *line == '#') continue; type = line; cur = line; while(*cur != ' ' && *cur != '\t' && *cur) cur++; if(*cur == 0) continue; *cur++ = 0; while(1) { while(*cur == ' ' || *cur == '\t') cur++; if(*cur == 0) break; ext = cur; while(*cur != ' ' && *cur != '\t' && *cur != '\n' && *cur) cur++; *cur++ = 0; if(*ext) { void *tmp; /* Add a new extension->type mapping */ mapping = malloc(sizeof(mime_type)); mapping->ext = strdup(ext); mapping->type = strdup(type); if (!avl_get_by_key (new_mimetypes, mapping, &tmp)) avl_delete (new_mimetypes, mapping, _delete_mapping); if (avl_insert (new_mimetypes, mapping) != 0) _delete_mapping (mapping); } } } fclose(mimefile); } while (0); thread_spin_lock (&pending_lock); old_mimetypes = mimetypes; mimetypes = new_mimetypes; thread_spin_unlock (&pending_lock); if (old_mimetypes) avl_tree_free (old_mimetypes, _delete_mapping); }
void global_shutdown(void) { thread_mutex_destroy(&_global_mutex); avl_tree_free(global.source_tree, source_free_source); }
void fserve_recheck_mime_types(ice_config_t *config) { FILE *mimefile; char line[4096]; char *type, *ext, *cur; mime_type *mapping; avl_tree *new_mimetypes; if (config->mimetypes_fn == NULL) return; mimefile = fopen (config->mimetypes_fn, "r"); if (mimefile == NULL) { ICECAST_LOG_WARN("Cannot open mime types file %s", config->mimetypes_fn); return; } new_mimetypes = avl_tree_new(_compare_mappings, NULL); while(fgets(line, 4096, mimefile)) { line[4095] = 0; if(*line == 0 || *line == '#') continue; type = line; cur = line; while(*cur != ' ' && *cur != '\t' && *cur) cur++; if(*cur == 0) continue; *cur++ = 0; while(1) { while(*cur == ' ' || *cur == '\t') cur++; if(*cur == 0) break; ext = cur; while(*cur != ' ' && *cur != '\t' && *cur != '\n' && *cur) cur++; *cur++ = 0; if(*ext) { void *tmp; /* Add a new extension->type mapping */ mapping = malloc(sizeof(mime_type)); mapping->ext = strdup(ext); mapping->type = strdup(type); if (!avl_get_by_key (new_mimetypes, mapping, &tmp)) avl_delete (new_mimetypes, mapping, _delete_mapping); avl_insert (new_mimetypes, mapping); } } } fclose(mimefile); thread_spin_lock (&pending_lock); if (mimetypes) avl_tree_free (mimetypes, _delete_mapping); mimetypes = new_mimetypes; thread_spin_unlock (&pending_lock); }