Exemple #1
0
void tracy_free(struct tracy* t) {
    /* Free hooks list */
    ll_free(t->hooks);

    /* Free all children */
    free_children(t->childs);
    ll_free(t->childs);

    free(t);
}
Exemple #2
0
int main(int argc, char** argv) {
    struct tracy *tracy;

    ll = ll_init();
    tracy = tracy_init(TRACY_TRACE_CHILDREN);

    if (argc < 2) {
        printf("Usage: county <program name> <program arguments>\n");
        return EXIT_FAILURE;
    }

    if (tracy_set_default_hook(tracy, all)) {
        printf("Failed to hook default hook.\n");
        return EXIT_FAILURE;
    }

    argv++; argc--;
    if (!tracy_exec(tracy, argv)) {
        perror("tracy_exec returned NULL");
        return EXIT_FAILURE;
    }

    tracy_main(tracy);

    tracy_free(tracy);

    print_stats();

    ll_free(ll);

    return 0;
}
/*
 *	Functionality for pthread_mutex_unlock()
 */
int mypthread_mutex_unlock(mypthread_mutex_t *mutex) {
	sem_wait(&mutex_sem);
	mutex->lock = false;
	ll_free(&(mutex->blocked_q_head), &(mutex->blocked_q_tail));
	sem_post(&mutex_sem);
	return 0;
}
Exemple #4
0
//-----------------------------------------------------------------------------
static void req_free(rq_http_req_t *req)
{
	param_t *param;
	
	assert(req);

	assert(req->reply);
	assert(BUF_LENGTH(req->reply) == 0);
	req->reply = expbuf_free(req->reply);
	assert(req->reply == NULL);

	// if the message is not NULL, then it means that we didn't send off the reply.  
	assert(req->msg == NULL);

	if (req->param_list) {
		assert(req->params);
		while((param = ll_pop_head(req->param_list))) {
			assert(param->key);
			free(param->key);
			assert(param->value);
			free(param->value);
			free(param);
		}
		req->param_list = ll_free(req->param_list);
		assert(req->param_list == NULL);
	}

	if (req->host)   { free(req->host); }
	if (req->path)   { free(req->path); }
	if (req->params) { free(req->params); }

	free(req);
}
Exemple #5
0
static t_ll *find_cols_rec(t_ll *files, int c, int width)
{
  t_ll *cols;
  t_ll *more_cols;
  t_ll *file;
  int i;
  int max;
  int len;

  cols = init_cols(c);
  for (i = 0, file = files; file != NULL; i++, file = file->next)
  {
    max = COLSIZE_AT(i);
    len = my_strlen(FINFO_LL_FILENAME(file)) + g_opts->filetypesymb;
    if (len > max)
    {
      COLSIZE_AT(i) = len;
    }
  }
  
  if (columns_too_large(cols, width))
  {
    ll_free(cols);
    return (NULL);
  }
  more_cols = find_cols_rec(files, c + 1, width);
  return (more_cols != NULL) ? more_cols : cols;
}
Exemple #6
0
void rq_http_free(rq_http_t *http)
{
	assert(http);

	assert(http->risp);
	http->risp = risp_shutdown(http->risp);
	assert(http->risp == NULL);

	if (http->safe_buffer) {
		assert(http->safe_len >= 0);
		free(http->safe_buffer);
		http->safe_buffer = NULL;
		http->safe_len = 0;
	}
	
	assert(http->queue);
	free(http->queue);
	http->queue  = NULL;

	http->rq = NULL;
	http->handler = NULL;
	http->arg = NULL;

	assert(http->req_list);
	assert(ll_count(http->req_list) == 0);
	http->req_list = ll_free(http->req_list);
	assert(http->req_list == NULL);

	free(http);
}
Exemple #7
0
void sll_free(struct sortedll_st* sll)
{
	if (sll)
	{
		ll_free(sll->ll);
		free(sll);
	}
}
Exemple #8
0
void queue_free(Queue *q){
	if(q->l != NULL)
	{
		ll_free(q->l);
	}
    q->l = NULL;
    free(q);
}
Exemple #9
0
static int on_accepted(const struct jbxm_initconf_st* iconf,
                       struct jbxm_callback_if_st* cbif)
{
    assert(iconf);
    assert(cbif);
    assert(cbif->type == JBXM_CBT_ACCEPTED);

    bool success = false;

    struct UserData_st* ud = calloc(1, sizeof(struct UserData_st));
    if (! ud)
    {
        fprintf(stderr, "error: calloc (errno=%d)\n", errno);

        goto EXIT_LABEL;
    }

// set ud members

    ud->headers = hm_init(19);
    if (! ud->headers)
    {
        fprintf(stderr, "error: hm_init\n");

        goto EXIT_LABEL;
    }

    ud->body_chunks = ll_init(free_varmem);
    if (! ud->body_chunks)
    {
        fprintf(stderr, "error: ll_init\n");

        goto EXIT_LABEL;
    }

// save to memory

    dbSET0(cbif, "user-data", ud);

    success = true;

EXIT_LABEL:

    if (! success)
    {
        if (ud)
        {
            hm_free(ud->headers);
            ll_free(ud->body_chunks);

            free(ud);
        }

        return -1;
    }

    return 0;
}
Exemple #10
0
//-----------------------------------------------------------------------------
// Cleanup the resources allocated int he settings object.   Currently this
// just includes the list of controllers.
void settings_cleanup(settings_t *ptr) 
{
	char *str;
	
	assert(ptr != NULL);

	while ((str = ll_pop_head(ptr->interfaces))) { free(str); }
	assert(ll_count(ptr->interfaces) == 0);
	ll_free(ptr->interfaces);
	free(ptr->interfaces);
	ptr->interfaces = NULL;
	
	while ((str = ll_pop_head(ptr->controllers))) { free(str); }
	assert(ll_count(ptr->controllers) == 0);
	ll_free(ptr->controllers);
	free(ptr->controllers);
	ptr->controllers = NULL;
}
/*
 *	Functionality for pthread_cond_broadcast()
 */
int mypthread_cond_broadcast(mypthread_cond_t *cond) {
	sem_wait(&cond_sem);
	sem_wait(&mypthread_sem);
	//Make active all threads sleeping on cond variable
	ll_free(&(cond->cond_q_head), &(cond->cond_q_tail));
	sem_post(&mypthread_sem);
	sem_post(&cond_sem);
	return 0;
}
Exemple #12
0
Fichier : rqd.c Projet : hyper/rqd
// nodelist should already be empty, otherwise how did we break out of the loop?
static void cleanup_nodes(system_data_t *sysdata)
{
	assert(sysdata);
	assert(sysdata->nodelist);

	assert(ll_count(sysdata->nodelist) == 0);
	ll_free(sysdata->nodelist);
	free(sysdata->nodelist);
	sysdata->nodelist = NULL;
}
Exemple #13
0
int main(void) {
  LinkedList* list = ll_new(0);
  for(size_t i =1;i<=5;i++)
    ll_insert(list,i,i-1);
  ll_print(list);
  
  list = ll_reverse(list);
  ll_print(list);

  ll_free(list);
  return EXIT_SUCCESS;
}
Exemple #14
0
/* Free the memory allocated for the sk_list
*/
int sk_free()
{
   SK_P FAR *sk_ptr;

   ll_access(&sk_list);
   while ((sk_ptr = (SK_P FAR *)ll_next(&sk_list)) != NULL) {
      MEM_UNLOCK(&sk_ptr->ptr->sk_val);
      FREE(&sk_ptr->ptr->sk_val);
   }
   ll_deaccess(&sk_list);
   ll_free(&sk_list);
   return( db_status );
}
Exemple #15
0
static void config_unload(control_t *control) {
	entry_t *entry;

	assert(control);
	while ((entry = ll_pop_head(control->entries))) {
		free(entry);
	}
	ll_free(control->entries);
	free(control->entries);
	control->entries = NULL;
	control->start = 0;
	control->end = 0;
}
void run_linked_list_tests() {
  char* inputs[] = {
    "item1",
    "item2",
    "item3",
  };
  int   num_inputs = sizeof(inputs) / sizeof(char*);
  char* data;

  // after init
  LinkedList *ll = ll_new();
  assert("Starts empty",      ll_is_empty(ll));
  assert("Initial size is 0", ll_size(ll)==0);
  assert("Peek returns null", ll_peek(ll)==NULL);

  // after pushing one item
  ll_push(ll, inputs[0]);
  assert("Is not empty after pushing an item",  !ll_is_empty(ll));
  assert("Has size of 1 after pushing an item", ll_size(ll)==1);
  assert("Peeking returns the item we pushed",  ll_peek(ll)==inputs[0]);

  // after two items
  ll_push(ll, inputs[1]);
  assert("Is not empty after pushing a second item",  !ll_is_empty(ll));
  assert("Has size of 2 after pushing a second item", ll_size(ll)==2);
  assert("Peeking returns the second item",           ll_peek(ll)==inputs[1]);

  // after three items
  ll_push(ll, inputs[2]);
  assert("Is not empty after pushing a third item",  !ll_is_empty(ll));
  assert("Has size of 3 after pushing a third item", ll_size(ll)==3);
  assert("Peeking returns the third item",           ll_peek(ll)==inputs[2]);

  // iterating through the items
  int index     = num_inputs;
  int all_match = 1;
  ll_each(ll, char* input, ({
    all_match &= (inputs[--index] == input);
  }));
  assert("It iterates the correct number of times", index==0);
  assert("The item provided matched each time",     all_match);

  // popping an item
  data = ll_pop(ll);
  assert("It is not empty after popping the third item", !ll_is_empty(ll));
  assert("Has size of 2 after popping the third item",   ll_size(ll)==2);
  assert("Peeking returns the second item",              ll_peek(ll)==inputs[1]);

  // cleanup
  ll_free(ll);
}
Exemple #17
0
int main( int argc, char** argv){
  int d = 0, quit = 1, commandNum, numRead;
  char *input, command;
  Line l = line_init(stdin);
  Ll ll = ll_init();

  gen_parse_args( argc, argv, &d);

  while( quit){
    printf("Command: ");
    line_read_line( l);
    input = get_line( l);
    sscanf(input, " %c%n", &command, &numRead);
    switch( command){
      case 'q': quit = 0; break;
      case 'i': if( gen_exists_num( input+numRead) ){
                sscanf(input+numRead, "%d", &commandNum);
                ll_insert( ll, commandNum , d);
              }
              else printf("Sorry, you didn't enter a number!\n");
              break;
      case 'd': if( gen_exists_num( input+numRead) ){
                sscanf( input+numRead, "%d", &commandNum);
                ll_delete( ll, commandNum, d);
              }
              else printf("Sorry, you didn't enter a number!\n");
              break;
      case 'c': if( gen_exists_num( input+numRead) ){
                  sscanf( input+numRead, "%d", &commandNum);
                  if( ll_contains( ll, commandNum, d) )
                    printf("LIST DOES CONTAIN %d\n", commandNum);
                  else printf("LIST DOES NOT CONATAIN %d\n", commandNum);
                }
                else printf("Sorry, you didn't enter a number!\n");
                break;
      case 'e': ll_empty( ll, d); break;
      case 'l': ll_print( ll, d); break;
      case 'r': ll_print_rev( ll, d); break;
      case '?': gen_print_help(); break;
      case 'h': gen_print_help(); break;
      case '\n': break;
      default: printf("Invalid Command\n");
    }
    free( input);    
  }

  ll_free( ll, d);
  line_free( l);
  return 0;
}
Exemple #18
0
void hm_free(struct hashmap_st* hm)
{
	if (hm)
	{
		struct lnklst_st** end = &hm->array[hm->array_num];

		for (struct lnklst_st** pos=hm->array; pos != end; pos++)
		{
			ll_free(*pos);
		}

		free(hm->array);
		free(hm);
	}
}
Exemple #19
0
Fichier : rqd.c Projet : hyper/rqd
// The queue list would not be empty, but the queues themselves should already be cleared as part of the server shutdown event.
static void cleanup_queues(system_data_t *sysdata)
{
 	queue_t *q;
 	
	assert(sysdata);
	assert(sysdata->queues);

	while ((q = ll_pop_head(sysdata->queues))) {
		queue_free(q);
		free(q);
	}
	assert(ll_count(sysdata->queues) == 0);
	ll_free(sysdata->queues);
	free(sysdata->queues);
	sysdata->queues = NULL;
}
Exemple #20
0
Fichier : rqd.c Projet : hyper/rqd
// cleanup the list of controllers.
static void cleanup_controllers(system_data_t *sysdata)
{
	controller_t *ct;

	assert(sysdata);
	assert(sysdata->controllers);

	while ((ct = ll_pop_head(sysdata->controllers))) {
		controller_free(ct);
		free(ct);
	}
	assert(ll_count(sysdata->controllers) == 0);
	ll_free(sysdata->controllers);
	free(sysdata->controllers);
	sysdata->controllers = NULL;
}
Exemple #21
0
int ll_check(){
    printf("Testing Linked Lists Functions\n");
    LinkList *l;

    counter = 0;

    l = ll_init(); assert_i(ll_size(l), 0, "Check LL Size after init");
    //ll_print(l);

    ll_addFront(l, 1, -1); assert_i(ll_size(l), 1, "Check LL Size after addFront");
    ll_addFront(l, 2, -2); assert_i(ll_size(l), 2, "Check LL Size after addFront");
    ll_addFront(l, 3, -3); assert_i(ll_size(l), 3, "Check LL Size after addFront");
    //ll_print(l);

    ll_addBack(l, 4, -4); assert_i(ll_size(l), 4, "Check LL Size after addBack");
    ll_addBack(l, 5, -5); assert_i(ll_size(l), 5, "Check LL Size after addBack");
    ll_addBack(l, 6, -6); assert_i(ll_size(l), 6, "Check LL Size after addBack");
    //ll_print(l);

    int x, y;
    ll_getFront(l, &x, &y); 
        assert_p(x, y, 3, -3, "Check LL getFront");
        assert_i(ll_size(l), 5, "Check LL Size after getFront");
    ll_getFront(l, &x, &y);
        assert_p(x, y, 2, -2, "Check LL getFront");
        assert_i(ll_size(l), 4, "Check LL Size after getFront");
    ll_getFront(l, &x, &y);
        assert_p(x, y, 1, -1, "Check LL getFront");
        assert_i(ll_size(l), 3, "Check LL Size after getFront");
    ll_getFront(l, &x, &y);
        assert_p(x, y, 4, -4, "Check LL getFront");
        assert_i(ll_size(l), 2, "Check LL Size after getFront");
    ll_getFront(l, &x, &y);
        assert_p(x, y, 5, -5, "Check LL getFront");
        assert_i(ll_size(l), 1, "Check LL Size after getFront");
    ll_getFront(l, &x, &y);
        assert_p(x, y, 6, -6, "Check LL getFront");
        assert_i(ll_size(l), 0, "Check LL Size after getFront");

    ll_addBack(l, 2, 3); assert_i(ll_size(l), 1, "Check LL Size after addBack on Empty List");
    ll_getFront(l, &x, &y);
        assert_p(x, y, 2, 3, "Check LL getFront");
        assert_i(ll_size(l), 0, "Check LL Size after getFront");


    ll_free(l);
}
Exemple #22
0
Fichier : rqd.c Projet : hyper/rqd
// cleanup 'server'
static void cleanup_servers(system_data_t *sysdata)
{
	server_t *server;
	
	assert(sysdata);
	assert(sysdata->servers);

	while ((server = ll_pop_head(sysdata->servers))) {
		server_free(server);
		free(server);
	}

	assert(ll_count(sysdata->servers) == 0);
	sysdata->servers = ll_free(sysdata->servers);
	assert(sysdata->servers == NULL);
	sysdata->servers = NULL;
}
Exemple #23
0
void ll_free_recur(LList* list) {
  //assert existence
  assert(list != NULL);
  if (list->length > 0) {

    //INVARIANT: curr is non-NULL
    LNode* curr = list->head;
    LNode* child = curr->next;

    while (child != NULL) {
      ln_free_recur(curr);
      curr = child;
      child = child->next;
    }

    // INVARIANT: child == NULL
    ln_free_recur(curr);
  }
  ll_free(list);
}
Exemple #24
0
struct lnklst_st* new_lstnmods(struct lnklst_st* fkvs)
{
FUNC_ENTER

	struct sortedll_st* ports = NULL;
	struct lnklst_st* lstnmods = NULL;		// ports がユニークなので lnklst_t でよい

	ports = sll_init(NULL, cmp_as_long_, SLLOPT_DISALLOW_DUPVAL);
	if (! ports)
	{
		FIRE("sll_init");
	}

	syserr = ll_foreach(fkvs, collect_port_, ports);
	if (syserr)
	{
		FIRE("ll_foreach");
	}

	lstnmods = new_lstnmods_(ports, fkvs);
	if (! lstnmods)
	{
		FIRE("new_lstnmods_");
	}

FUNC_CHECKPOINT

	if (HAS_ERROR())
	{
		ll_free(lstnmods);
		lstnmods = NULL;
	}

	sll_free(ports);
	ports = NULL;

FUNC_LEAVE

	return lstnmods;
}
Exemple #25
0
int main() {
  log_info("Creating a linked list.");
  LinkedList* list = ll_new();
  check(list->first == NULL, "List was not correctly initialised.");
  check(list->length == 0, "List should not have any elements.");

  log_info("Adding an element to the list.");
  int v = 1337;
  int* vpointer = malloc(sizeof(int));
  *vpointer = v;
  ll_prepend(list, vpointer);
  check(list->length == 1, "Length increment failed");
  check(list->first != NULL, "Append failed");
  check(list->first->data == vpointer, "Bad address");
  log_info("The address of list->first->data %p",
      list->first->data);
  check(*((int*) list->first->data) == v, "Bad value");
  log_info("The value is %d as expected",
      *((int*) list->first->data));

  log_info("Adding another element.");
  v = 1338;
  int* another = malloc(sizeof(int));
  *another = v;
  ll_prepend(list, another);
  check(list->length == 2, "Length increment failed");
  check(*((int*) list->first->data) == v, "List increment screwed up");

  log_info("Checking list[0].");
  check(*((int*) ll_get(list, 0)) == v, "First element does not match what was last prepended.");
  log_info("Checking list[1].");
  check(*((int*) ll_get(list, 1)) == 1337, "First element does not match what was first prepended.");

  log_info("Freeing the linked list.");
  ll_free(list);
  return 0;
error:
  return 1;
}
Exemple #26
0
static int on_disconnect(const struct jbxm_initconf_st* iconf,
	struct jbxm_callback_if_st* cbif)
{
	assert(iconf);
	assert(cbif);
	assert(cbif->type == JBXM_CBT_DISCONNECT);

	struct UserData_st* ud = NULL;
	dbUNSET(cbif, "user-data", &ud);
	assert(ud);

	if (ud->luaS)
	{
		lua_close(ud->luaS);
		ud->luaS = NULL;
	}

	ll_free(ud->chunks);

	free(ud);

	return 0;
}
Exemple #27
0
static int on_disconnect(const struct jbxm_initconf_st* iconf,
                         struct jbxm_callback_if_st* cbif)
{
    assert(iconf);
    assert(cbif);
    assert(cbif->type == JBXM_CBT_DISCONNECT);

    struct UserData_st* ud = NULL;
    dbUNSET(cbif, "user-data", &ud);
    assert(ud);

    free(ud->method);
    free(ud->path);
    free(ud->response);

    hm_clear(ud->headers, free_header_);
    hm_free(ud->headers);

    ll_free(ud->body_chunks);

    free(ud);

    return 0;
}
static void free_fdinfo_list(struct tracy_ll *ll)
{
	struct tracy_ll_item *t;

	t = ll->head;

	// free custom fields
	while (t) {
		if (t->data) {
			struct fd_info *fdi = t->data;
			if (fdi) {
				WARNING("unclosed file: %d(%s)\n", t->id,
					fdi->filename);
				free_fdinfo(fdi);
				t->data = NULL;
			}
		}

		t = t->next;
	}

	// free the list itself
	ll_free(ll);
}
Exemple #29
0
void rq_blacklist_free(rq_blacklist_t *blacklist)
{
	cache_entry_t *tmp;
	
	assert(blacklist);
	assert(blacklist->rq);
	assert(blacklist->queue);
	assert(blacklist->expires > 0);
	assert(blacklist->cache);

	blacklist->rq = NULL;
	blacklist->queue = NULL;

	assert(blacklist->risp);
	risp_shutdown(blacklist->risp);
	blacklist->risp = NULL;

	while ((tmp = ll_pop_head(blacklist->cache))) {
		free(tmp);
	}
	ll_free(blacklist->cache);
	free(blacklist->cache);
	blacklist->cache = NULL;
}
Exemple #30
0
/**
 * Cleans up after all tests have been run, cleans up all global variables
 */
void clean_up(){
	ll_free(problems);
}