示例#1
0
char *create_file_list(struct pkginfo *dpkg, psys_flist_t files,
		       psys_err_t *err)
{
	char *path;
	FILE *list;
	void *ftree;
	psys_flist_t f;

	if (create_list(dpkg, "list", &path, &list, err))
		return NULL;

	ftree = NULL;
	for (f = files; f; f = psys_flist_next(f)) {
		if (add_to_file_list(list, psys_flist_path(f), &ftree, err)) {
			tdestroy(ftree, ftree_destroy_fn);
			fclose(list);
			remove(path);
			free(path);
			return NULL;
		}
	}

	tdestroy(ftree, ftree_destroy_fn);
	fclose(list);
	return path;
}
示例#2
0
void tdestroy(void *root, void (*freekey)(void *))
{
	struct node *r = root;

	if (r == 0)
		return;
	tdestroy(r->left, freekey);
	tdestroy(r->right, freekey);
	if (freekey) freekey(r->key);
	free(r);
}
示例#3
0
void
internal_function
__libdw_destroy_frame_cache (Dwarf_CFI *cache)
{
  /* Most of the data is in our two search trees.  */
  tdestroy (cache->fde_tree, free_fde);
  tdestroy (cache->cie_tree, free_cie);
  tdestroy (cache->expr_tree, free_expr);

  if (cache->ebl != NULL && cache->ebl != (void *) -1l)
    ebl_closebackend (cache->ebl);
}
示例#4
0
void var_DestroyAll( vlc_object_t *obj )
{
    vlc_object_internals_t *priv = vlc_internals( obj );

    tdestroy( priv->var_root, CleanupVar );
    priv->var_root = NULL;
}
示例#5
0
static
void count_path(const char *path, int flags, int bs)
{
	int olderrcnt = errcnt;

	used_blocks = used_inodes = 0;

	if (inotable)
		tdestroy(inotable, inofree);

	inotable = NULL;

	nftw(path, handle_file, 50, flags);

	printf("%s", path);

	if (errcnt > olderrcnt)
		printf(" ERR");

	else if (do_hr) {
		if (do_space)
			printf(" %s", pretty_mem(used_blocks * 512 / bs));
		if (do_inode)
			printf(" %s", pretty_ino(used_inodes));
	}

	else {
		if (do_space)
			printf(" %" PRIu64, used_blocks * 512 / bs);
		if (do_inode)
			printf(" %" PRIu64, used_inodes);
	}

	printf("\n");
}
示例#6
0
文件: ptl_conn.c 项目: foool/portals4
/**
 * Destroys all connections belonging to an NI
 */
void destroy_conns(ni_t *ni)
{
    if (ni->options & PTL_NI_LOGICAL) {
        if (ni->logical.mapping) {
            int i;
            const int map_size = ni->logical.map_size;

            /* Destroy active connections. */
            for (i = 0; i < map_size; i++) {
                entry_t *entry = &ni->logical.rank_table[i];
                destroy_conn(entry->connect);
                entry->connect = NULL;
            }
        }
    } else {
#ifdef HAVE_TDESTROY
        tdestroy(ni->physical.tree, destroy_conn);
#else
        while (ni->physical.tree != NULL) {
            destroy_conn(*(void **)ni->physical.tree);
            tdelete(*(void **)ni->physical.tree, &ni->physical.tree,
                    compare_conn_id);
        }
#endif
    }
}
示例#7
0
/*
 * ===  FUNCTION  ======================================================================
 *         Name:  process_queue
 *  Description:  Reads messages from queue and places them in a search tree
 *                using the tsearch() function.  When all messages have been read, traverses
 *                the tree, sending messages based upon the alphabetical order of the mtext
 *                field.
 * =====================================================================================
 */
static int
process_queue(int msqid, size_t maxmsgsz, long msgtyp, int msgflg,
        int(*compar)(const void *, const void *),
        void (*action)(const void *nodep, const VISIT value, const int level))
{
    int ret;
    msg_t *msg = NULL, *msg_node = NULL;
    void *root = NULL, *node = NULL;
    int msgsnd_flag = 0;

    while(1) {
        /* Each node of the tree must be separately
         * allocated. */
        msg = xmalloc(sizeof(msg_t));
        ret = msgrcv(msqid, msg, maxmsgsz, msgtyp, msgflg);
        if(ret == -1) {
            perror("process_queue: msgrcv");
            _exit(EXIT_FAILURE);
        }
        /* If msg's count field == -1, there are
         * no more messages to process. */
        if(msg->count == -1) {
            free(msg);
            break;
        }
        node = tsearch(msg, &root, compar);
        /* If 'node' is NULL, tsearch failed to insert
         * the message into the tree. */
        if(node == NULL) {
            perror("tsearch");
            _exit(EXIT_FAILURE);
        } else {
            msg_node = *(msg_t **)node;
            /* Check whether the newly-inserted node
             * points to the same place as 'msg'.  If it
             * doesn't, increment the node's count field
             * and free msg. */
            if(msg_node != msg) {
                msg_node->count++;
                free(msg);
            }
        }
    }

    /* Place messages in queue in
     * alphabetical order */
    twalk(root, action);

    /* Free the memory associated
     * with the tree */
    tdestroy(root, &free);

    /* Send terminating message to parent */
    if(msgsnd_str(child_queue, 1, msgsnd_flag, msgtyp, "", -1) == -1) {
        perror("msgsnd_str");
        _exit(EXIT_FAILURE);
    }

    return ret;
}
/**
 * Frees all internal memory associated with the dictionary. Must be called last.
 */
void dictionary_destroy(dictionary_t *d)
{
	tdestroy(d->root, destroy_no_element_free);
	d->root = NULL;

	pthread_mutex_destroy(&d->mutex);
}
示例#9
0
文件: datastore.c 项目: Yankkk/C
void datastore_destroy(datastore_t *ds)
{
	tdestroy(ds->root, destroy_with_element_free);
	ds->root = NULL;

	pthread_mutex_destroy(&ds->mutex);
}
示例#10
0
文件: tree_tests.c 项目: imej/c
char *test_getvar()
{
    char line[] = "how are you?";
    char rv[MAXLINE] = {0};
    struct tnode *tree = createKeyTree();
    int i = 0;
     
    i = getvar(line, i, tree, rv);
    
    mu_assert(i == 3, "the first word should be ended at position 3");
    mu_assert(strcmp(rv,"how") == 0, "the first word is not 'how'");

    i = getvar(line, i, tree, rv);
    
    mu_assert(i == 7, "the second word should be ended at position 7");
    mu_assert(strcmp(rv,"are") == 0, "the second word is not 'are'");
    
    i = getvar(line, i, tree, rv);
    
    mu_assert(i == 11, "the second word should be ended at position 11");
    mu_assert(strcmp(rv,"you") == 0, "the third word is not 'you'");
    
    i = getvar(line, i, tree, rv);
    
    mu_assert(i == -1,"the fourth word does not exist");
    
    tdestroy(tree);

    return NULL;
}
void
internal_function
__libdwfl_module_free (Dwfl_Module *mod)
{
  if (mod->lazy_cu_root != NULL)
    tdestroy (mod->lazy_cu_root, nofree);

  if (mod->aranges != NULL)
    free (mod->aranges);

  if (mod->cu != NULL)
    {
      for (size_t i = 0; i < mod->ncu; ++i)
	free_cu (mod->cu[i]);
      free (mod->cu);
    }

  if (mod->dw != NULL)
    INTUSE(dwarf_end) (mod->dw);

  if (mod->ebl != NULL)
    ebl_closebackend (mod->ebl);

  if (mod->debug.elf != mod->main.elf)
    free_file (&mod->debug);
  free_file (&mod->main);

  if (mod->build_id_bits != NULL)
    free (mod->build_id_bits);

  free (mod->name);
  free (mod);
}
示例#12
0
void
zmalloc_leaks(void)
{
#ifdef USE_TSEARCH
    TRACE(("zmalloc_leaks\n"));
    tdestroy(ptr_data, free_ptr_data);
#endif
}
示例#13
0
文件: tree_tests.c 项目: imej/c
char *test_ckeys()
{
    struct tnode *tree = createKeyTree();
    treeprint(tree);
    tdestroy(tree);

    return NULL;
}
示例#14
0
文件: tree.c 项目: imej/c
/* tdestroy: free tree - nodes and strings */
void tdestroy(struct tnode *rt)
{
    if (rt != NULL) {
        tdestroy(rt->left);
	tdestroy(rt->right);

	if (rt->word != NULL) {
	    free(rt->word);
	}

	if (rt->lnums != NULL) {
	    destroy_all_lnode(rt->lnums);
	}

	free(rt);
    }
}
示例#15
0
static void close_all_devs(void)
{
	dvb_fd = -1;
	numfds = 0;
	tdestroy(desc_root, free_opendevs);

	desc_root = NULL;
}
示例#16
0
文件: pulse.c 项目: 4udak/vlc
static void Close (vlc_object_t *obj)
{
    services_discovery_t *sd = (services_discovery_t *)obj;
    services_discovery_sys_t *sys = sd->p_sys;

    vlc_pa_disconnect (obj, sys->context, sys->mainloop);
    tdestroy (sys->root, DestroySource);
    free (sys);
}
示例#17
0
static void
cu_free (void *arg)
{
  struct Dwarf_CU *p = (struct Dwarf_CU *) arg;

  Dwarf_Abbrev_Hash_free (&p->abbrev_hash);

  tdestroy (p->locs, noop_free);
}
示例#18
0
/* One reason fewer to keep the lazy lookup table for CUs.  */
static inline void
less_lazy (Dwfl_Module *mod)
{
  if (--mod->lazycu > 0)
    return;

  /* We know about all the CUs now, we don't need this table.  */
  tdestroy (mod->lazy_cu_root, nofree);
  mod->lazy_cu_root = NULL;
}
示例#19
0
文件: tree_tests.c 项目: imej/c
char *test_prtgrp()
{
    char *sa[] = {"aaaa", "aaab", "aaac", "aabd", "aabe"};
    struct tnode *tree = fromSortedArray(sa, 0, 4);
    char grp[MAXLINE] = {0};

    prtgrp(tree, 3, grp);

    tdestroy(tree);

    return NULL;
}
示例#20
0
文件: xcb_apps.c 项目: IAPark/vlc
/**
 * Releases resources
 */
static void Close (vlc_object_t *obj)
{
    services_discovery_t *sd = (services_discovery_t *)obj;
    services_discovery_sys_t *p_sys = sd->p_sys;

    vlc_cancel (p_sys->thread);
    vlc_join (p_sys->thread, NULL);
    xcb_disconnect (p_sys->conn);
    tdestroy (p_sys->apps, DelApp);
    if (p_sys->apps_root != NULL)
        input_item_Release(p_sys->apps_root);
    free (p_sys);
}
示例#21
0
文件: realms.c 项目: bagdxk/openafs
/**
 * Delete all the entries from the search tree.
 *
 * @param[in] list  list of entries
 *
 * @return none
 *
 * @internal
 */
/*static*/ void
destroy_tree(struct afsconf_realms *entries)
{
    if (entries->tree) {
#if HAVE_TDESTROY
	tdestroy(entries->tree, free_tree_node);
#else
	struct opr_queue *cursor;
	struct afsconf_realm_entry *entry;

	for (opr_queue_Scan(&entries->list, cursor)) {
	    entry = opr_queue_Entry(cursor, struct afsconf_realm_entry, link);
	    tdelete(entry->value, &entries->tree, entries->compare);
	}
#endif
	entries->tree = NULL;
    }
示例#22
0
文件: xcb_apps.c 项目: IAPark/vlc
static void UpdateApps (services_discovery_t *sd)
{
    services_discovery_sys_t *p_sys = sd->p_sys;
    xcb_connection_t *conn = p_sys->conn;

    xcb_get_property_reply_t *r =
        xcb_get_property_reply (conn,
            xcb_get_property (conn, false, p_sys->root_window,
                              p_sys->net_client_list, XA_WINDOW, 0, 1024),
            NULL);
    if (r == NULL)
        return; /* FIXME: remove all entries */

    xcb_window_t *ent = xcb_get_property_value (r);
    int n = xcb_get_property_value_length (r) / 4;
    void *newnodes = NULL, *oldnodes = p_sys->apps;

    for (int i = 0; i < n; i++)
    {
        xcb_window_t id = *(ent++);
        struct app *app;

        struct app **pa = tfind (&id, &oldnodes, cmpapp);
        if (pa != NULL) /* existing entry */
        {
            app = *pa;
            tdelete (app, &oldnodes, cmpapp);
        }
        else /* new entry */
        {
            app = AddApp (sd, id);
            if (app == NULL)
                continue;
        }

        pa = tsearch (app, &newnodes, cmpapp);
        if (pa == NULL /* OOM */ || *pa != app /* buggy window manager */)
            DelApp (app);
    }
    free (r);

    /* Remove old nodes */
    tdestroy (oldnodes, DelApp);
    p_sys->apps = newnodes;
}
示例#23
0
文件: udev.c 项目: etix/vlc
/**
 * Releases resources
 */
static void Close (vlc_object_t *obj)
{
    services_discovery_t *sd = (services_discovery_t *)obj;
    services_discovery_sys_t *p_sys = sd->p_sys;

    if (p_sys->monitor != NULL)
    {
        struct udev *udev = udev_monitor_get_udev (p_sys->monitor);

        vlc_cancel (p_sys->thread);
        vlc_join (p_sys->thread, NULL);
        udev_monitor_unref (p_sys->monitor);
        udev_unref (udev);
    }

    tdestroy (p_sys->root, DestroyDevice);
    free (p_sys);
}
示例#24
0
void override_free(struct overridefile *info) {
	struct overridepattern *i;

	if (info == NULL)
		return;

#ifdef HAVE_TDESTROY
	tdestroy(info->packages, freeoverridepackage);
#endif
	while ((i = info->patterns) != NULL) {
		if (i == NULL)
			return;
		strlist_done(&i->data.fields);
		free(i->pattern);
		info->patterns = i->next;
		free(i);
	}
	free(info);
}
示例#25
0
uint32_t arrayMinCoverage_eval(struct array* array, uint32_t nb_category, struct categoryDesc* desc_buffer, int32_t(*compare)(const void*,const void*)){
	uint32_t 					i;
	uint32_t 					j;
	struct array* 				element_array;
	uint32_t 					nb_tag 			= 0;
	void* 						tree_root 		= NULL;
	struct tagMapTreeToken* 	new_token 		= NULL;
	struct tagMapTreeToken** 	result;

	for (i = 0; i < nb_category; i++){
		element_array = *(struct array**)array_get(array, desc_buffer[i].offset + desc_buffer[i].choice);
		for (j = 0; j < array_get_length(element_array); j++){
			if (new_token == NULL){
				if ((new_token = malloc(sizeof(struct tagMapTreeToken))) == NULL){
					log_err("unable to allocate memory");
					goto exit;
				}
			}

			new_token->element = array_get(element_array, j);
			new_token->idx = nb_tag;

			result = tsearch(new_token, &tree_root, compare);
			if (result == NULL){
				log_err("tsearch failed to insert new item");
				goto exit;
			}
			else if (*result == new_token){
				new_token = NULL;
				nb_tag ++;
			}
		}
	}

	exit:
	if (new_token != NULL){
		free(new_token);
	}
	tdestroy(tree_root, free);

	return nb_tag;
}
示例#26
0
文件: hashtable.c 项目: huyna/sftc
void
hash_table_free(struct hash_table *hash, void (*action)(void *))
{
	unsigned int i;

	/* For thread safety */
	while (hash->foo != NULL)
		;

	hash->foo=(void*)action;

	for (i=0; i < hash->size; i++)
		if (hash->table[i] != NULL)
		{
			tdestroy(hash->table[i]->tree,hash_tree_free_node);
			free(hash->table[i]);
		}

	free(hash->table);
}
示例#27
0
文件: tree_tests.c 项目: imej/c
char *test_tree()
{
    struct tnode *tree = NULL;
    struct tnode *root = NULL;

    tree = addtree(tree, "I");
    mu_assert(tree != NULL, "Failed to add \"I\" to tree.");
    root = tree;

    tree = addtree(tree, "hate");
    mu_assert(tree != NULL, "Failed to add \"hate\" to tree.");
    
    tree = addtree(tree, "whole wheet");
    mu_assert(tree != NULL, "Failed to add \"whole wheet\" to tree.");

    /* treeprint(root); */
    tdestroy(root);

    return NULL;
}
示例#28
0
int
main( void )
{
  int i, *ptr;
  void *val;

  srand( time( NULL ) );
  for ( i = 0; i < 12; i++ )
  {
    ptr = xmalloc( sizeof( int ) );
    *ptr = rand(  ) & 0xff;
    val = tsearch( ( void * ) ptr, &root, compare );
    if ( val == NULL )
      exit( EXIT_FAILURE );
    else if ( ( *( int ** ) val ) != ptr )
      free( ptr );
  }
  twalk( root, action );
  tdestroy( root, free );
  exit( EXIT_SUCCESS );
}
示例#29
0
文件: tree_tests.c 项目: imej/c
char *test_fromSortedArray()
{
    char *sa[] = {"aaa", "bbb", "ccc", "ddd", "eee"};

    struct tnode *tree = fromSortedArray(sa, 0, 4);

    mu_assert(strcmp(tree->word, sa[2]) == 0, "'ccc' is not root.");
    mu_assert(strcmp(tree->left->word, sa[0]) == 0, "'aaa' is not the first left.");
    mu_assert(strcmp(tree->right->word, sa[3]) == 0, "'ddd' is not the first left.");
    mu_assert(strcmp(tree->left->right->word, sa[1]) == 0, "'bbb' is not the first left.");
    mu_assert(strcmp(tree->right->right->word, sa[4]) == 0, "'eee' is not the first left.");

    mu_assert(intree(tree, sa[2]) == 1, "'ccc' is not in the tree.");
    mu_assert(intree(tree, sa[1]) == 1, "'bbb' is not in the tree.");
    mu_assert(intree(tree, "zzz") == 0, "'zzz' is in the tree.");

    /* treeprint(tree); */

    tdestroy(tree);

    return NULL;
}
示例#30
0
TEST(search, tfind_tsearch_twalk_tdestroy) {
  void* root = nullptr;

  node n1("z");
  node n2("a");
  node n3("m");

  // tfind(3) can't find anything in the empty tree.
  ASSERT_EQ(nullptr, tfind(&n1, &root, node_cmp));
  ASSERT_EQ(nullptr, tfind(&n2, &root, node_cmp));
  ASSERT_EQ(nullptr, tfind(&n3, &root, node_cmp));

  // tsearch(3) inserts and returns a pointer to a new node.
  void* i1 = tsearch(&n1, &root, node_cmp);
  ASSERT_NE(nullptr, i1);

  // ...which tfind(3) will then return.
  ASSERT_EQ(i1, tfind(&n1, &root, node_cmp));
  ASSERT_EQ(nullptr, tfind(&n2, &root, node_cmp));
  ASSERT_EQ(nullptr, tfind(&n3, &root, node_cmp));

  // Add the other nodes.
  ASSERT_NE(nullptr, tsearch(&n2, &root, node_cmp));
  ASSERT_NE(nullptr, tsearch(&n3, &root, node_cmp));

  // Use twalk(3) to iterate over the nodes.
  g_nodes.clear();
  twalk(root, node_walk);
  ASSERT_EQ(3U, g_nodes.size());
  ASSERT_EQ("a", g_nodes[0]);
  ASSERT_EQ("m", g_nodes[1]);
  ASSERT_EQ("z", g_nodes[2]);

  // tdestroy(3) removes nodes under a node, calling our callback to destroy each one.
  g_free_calls = 0;
  tdestroy(root, node_free);
  ASSERT_EQ(3U, g_free_calls);
}