/// Removes a node and its data static void onion_dict_node_free(onion_dict_node *node){ if (node->left) onion_dict_node_free(node->left); if (node->right) onion_dict_node_free(node->right); onion_dict_node_data_free(&node->data); onion_low_free(node); }
/** * @short Removes the full dict struct from mem. * @memberof onion_dict_t */ void onion_dict_free(onion_dict *dict){ #ifdef HAVE_PTHREADS pthread_mutex_lock(&dict->refmutex); #endif dict->refcount--; //ONION_DEBUG0("Free %p refcount %d", dict, dict->refcount); int remove=(dict->refcount==0); #ifdef HAVE_PTHREADS pthread_mutex_unlock(&dict->refmutex); #endif if(remove){ #ifdef HAVE_PTHREADS pthread_rwlock_destroy(&dict->lock); pthread_mutex_destroy(&dict->refmutex); #endif if (dict->root) onion_dict_node_free(dict->root); free(dict); } }