/** * Frees the whole memory associated to the given optimized state. */ static void free_optimized_state(OptimizedFst2State state,Abstract_allocator prv_alloc) { if (state==NULL) return; free_opt_graph_call(state->graph_calls,prv_alloc); free_opt_meta(state->metas,prv_alloc); free_opt_pattern(state->patterns,prv_alloc); free_opt_pattern(state->compound_patterns,prv_alloc); free_opt_token(state->token_list,prv_alloc); free_opt_variable(state->input_variable_starts,prv_alloc); free_opt_variable(state->input_variable_ends,prv_alloc); free_opt_variable(state->output_variable_starts,prv_alloc); free_opt_variable(state->output_variable_ends,prv_alloc); free_opt_contexts(state->contexts,prv_alloc); if (state->tokens!=NULL) free_cb(state->tokens,prv_alloc); if (state->token_transitions!=NULL) { for (int i=0;i<state->number_of_tokens;i++) { free_Transition_list(state->token_transitions[i],prv_alloc); } free_cb(state->token_transitions,prv_alloc); } free_opt_graph_call(state->unoptimized_graph_calls,prv_alloc); free_opt_meta(state->unoptimized_metas,prv_alloc); free_opt_variable(state->unoptimized_input_variable_starts,prv_alloc); free_opt_variable(state->unoptimized_input_variable_ends,prv_alloc); free_opt_variable(state->unoptimized_output_variable_starts,prv_alloc); free_opt_variable(state->unoptimized_output_variable_ends,prv_alloc); free_cb(state,prv_alloc); }
/** * Frees a single match list element. */ void free_match_list(struct match_list* l,Abstract_allocator prv_alloc) { while (l!=NULL) { struct match_list* ptr=l; l=l->next; if (ptr->output!=NULL) free_cb(ptr->output,prv_alloc); free_cb(ptr,prv_alloc); } }
/** * Frees all the memory asociated to the given token tree structure. */ void free_fst2txt_token_tree(struct fst2txt_token_tree* t, Abstract_allocator prv_alloc) { if (t==NULL) return; free_string_hash(t->hash); for (int i=0;i<t->size;i++) { free_Transition_list(t->transition_array[i], prv_alloc); } free_cb(t->transition_array,prv_alloc); free_cb(t,prv_alloc); }
/** * Frees all the memory associated to the given pattern. */ void free_pattern(struct pattern* p,Abstract_allocator prv_alloc) { if (p==NULL) return; if (p->inflected!=NULL) free_cb(p->inflected,prv_alloc); if (p->lemma!=NULL) free_cb(p->lemma,prv_alloc); free_list_ustring(p->grammatical_codes,prv_alloc); free_list_ustring(p->inflectional_codes,prv_alloc); free_list_ustring(p->forbidden_codes,prv_alloc); free_cb(p,prv_alloc); }
static void *rping_persistent_server_thread(void *arg) { struct rping_cb *cb = arg; struct ibv_recv_wr *bad_wr; int ret; ret = rping_setup_qp(cb, cb->child_cm_id); if (ret) { fprintf(stderr, "setup_qp failed: %d\n", ret); goto err0; } ret = rping_setup_buffers(cb); if (ret) { fprintf(stderr, "rping_setup_buffers failed: %d\n", ret); goto err1; } ret = ibv_post_recv(cb->qp, &cb->rq_wr, &bad_wr); if (ret) { fprintf(stderr, "ibv_post_recv failed: %d\n", ret); goto err2; } ret = pthread_create(&cb->cqthread, NULL, cq_thread, cb); if (ret) { perror("pthread_create"); goto err2; } ret = rping_accept(cb); if (ret) { fprintf(stderr, "connect error %d\n", ret); goto err3; } rping_test_server(cb); rdma_disconnect(cb->child_cm_id); pthread_join(cb->cqthread, NULL); rping_free_buffers(cb); rping_free_qp(cb); rdma_destroy_id(cb->child_cm_id); free_cb(cb); return NULL; err3: pthread_cancel(cb->cqthread); pthread_join(cb->cqthread, NULL); err2: rping_free_buffers(cb); err1: rping_free_qp(cb); err0: free_cb(cb); return NULL; }
/** * Frees a single match list element. */ void free_match_list_element(struct match_list* l,Abstract_allocator prv_alloc) { if (l==NULL) { return; } if (l->output!=NULL) { free_cb(l->output,prv_alloc); } free_cb(l,prv_alloc); // protecting against dangling pointer bugs l = NULL; }
/** * This function removes the tail of the given list. */ void delete_tail(struct list_int* *l,Abstract_allocator prv_alloc) { struct list_int* previous; if ((*l)==NULL) return; if ((*l)->next==NULL) { free_cb(*l,prv_alloc); *l=NULL; return; } previous=*l; while (previous->next->next!=NULL) { previous=previous->next; } free_cb(previous->next,prv_alloc); previous->next=NULL; }
/** * Frees a string_hash_tree. */ void free_arbre_hash(struct string_hash_tree_node* node,int free_tree_node_struct,int free_tree_transition_struct,struct string_hash* s) { if (node==NULL) return; free_string_hash_tree_transition(node->trans,free_tree_node_struct,free_tree_transition_struct,s); if (free_tree_node_struct) { free_cb(node,s->allocator_tree_node); } }
/** * Frees the whole memory associated to the given optimized state array. */ void free_optimized_states(OptimizedFst2State* states,int size,Abstract_allocator prv_alloc) { if (states==NULL) return; for (int i=0;i<size;i++) { free_optimized_state(states[i],prv_alloc); } free_cb(states,prv_alloc); }
/** * This function builds an array containing the token numbers stored * in the token list of the given state. As the token list is supposed * to be sorted, the array will be sorted. The function frees the token * list. */ static void token_list_2_token_array(OptimizedFst2State state,Abstract_allocator prv_alloc) { int i; struct opt_token* l; struct opt_token* tmp; if (state->number_of_tokens==0) { /* Nothing to do if there is no token in the list */ return; } state->tokens=(int*)malloc_cb(sizeof(int)*state->number_of_tokens,prv_alloc); if (state->tokens==NULL) { fatal_alloc_error("token_list_2_token_array"); } state->token_transitions=(Transition**)malloc_cb(sizeof(Transition*)*state->number_of_tokens,prv_alloc); if (state->token_transitions==NULL) { fatal_alloc_error("token_list_2_token_array"); } i=0; l=state->token_list; while (l!=NULL) { state->tokens[i]=l->token_number; state->token_transitions[i]=l->transition; i++; tmp=l; l=l->next; /* We must NOT free 'tmp->transition' since it is referenced now * in 'state->token_transitions[i]' */ free_cb(tmp,prv_alloc); } if (i!=state->number_of_tokens) { fatal_error("Internal error in token_list_2_token_array\n"); } state->token_list=NULL; }
void free_Transition(Transition* t,void(*free_elag_tag)(symbol_t*),Abstract_allocator prv_alloc) { if (t==NULL) return; if (free_elag_tag!=NULL && t->label!=NULL) { free_elag_tag(t->label); } free_cb(t,prv_alloc); }
/** * Frees a whole int list. */ void free_list_int(struct list_int* head,Abstract_allocator prv_alloc) { struct list_int* tmp; while (head!=NULL) { tmp=head; head=head->next; free_cb(tmp,prv_alloc); } }
/** * Frees all the memory associated to the given LocateCache, including * its match list, if any. */ void free_LocateCache(LocateCache c,Abstract_allocator prv_alloc) { if (c==NULL) return; free_LocateCache(c->left,prv_alloc); free_LocateCache(c->middle,prv_alloc); free_LocateCache(c->right,prv_alloc); free_match_list(c->matches,prv_alloc); free_cb(c,prv_alloc); }
/** * Frees the whole memory associated to the given list. We free the pointers * using the given 'free_pointer' function, if not NULL. */ void free_list_pointer(struct list_pointer* list,void (*free_pointer)(void*),Abstract_allocator prv_alloc) { struct list_pointer* tmp; while (list!=NULL) { tmp=list; list=list->next; if (free_pointer!=NULL) free_pointer(tmp->pointer); free_cb(tmp,prv_alloc); } }
/** * Frees all the memory associated to the given variable list. */ static void free_opt_variable(struct opt_variable* list,Abstract_allocator prv_alloc) { struct opt_variable* tmp; while (list!=NULL) { free_Transition_list(list->transition,prv_alloc); tmp=list; list=list->next; free_cb(tmp,prv_alloc); } }
/** * Frees the dictionary node transition 't', and all the dictionary graph whose root is * the dictionary node pointed out by 't'. */ void free_dictionary_node_transition(struct dictionary_node_transition* t,Abstract_allocator prv_alloc) { struct dictionary_node_transition* tmp; while (t!=NULL) { free(t->output); free_dictionary_node(t->node,prv_alloc); tmp=t; t=t->next; free_cb(tmp,prv_alloc); } }
/** * Tries to remove the first occurrence of the value 'n' in * the given list. Returns 1 if the element was there; 0 otherwise. */ int remove(int n,struct list_int** l,Abstract_allocator prv_alloc) { struct list_int* tmp; if (*l==NULL) return 0; if ((*l)->n==n) { tmp=*l; *l=(*l)->next; free_cb(tmp,prv_alloc); return 1; } tmp=*l; while (tmp->next!=NULL && tmp->next->n!=n) { tmp=tmp->next; } if (tmp->next==NULL) return 0; struct list_int* tmp2=tmp->next; tmp->next=tmp2->next; free_cb(tmp2,prv_alloc); return 1; }
/** * Frees all the memory associated to the given meta list. */ static void free_opt_meta(struct opt_meta* list,Abstract_allocator prv_alloc) { struct opt_meta* tmp; while (list!=NULL) { free_Transition_list(list->transition,prv_alloc); free_Transition_list(list->morphological_mode_ends,prv_alloc); tmp=list; list=list->next; free_cb(tmp,prv_alloc); } }
/** * This function returns a list that is the sorted merge of the two given lists. * Duplicate elements are freed, if any. */ struct list_int* destructive_sorted_merge(struct list_int* a,struct list_int* b,Abstract_allocator prv_alloc) { struct list_int* tmp; while (b!=NULL) { a=sorted_insert(b->n,a,prv_alloc); tmp=b; b=b->next; free_cb(tmp,prv_alloc); } return a; }
/** * Destroy an array, optionally free the data. */ void _eglDestroyArray(_EGLArray *array, void (*free_cb)(void *)) { if (free_cb) { EGLint i; for (i = 0; i < array->Size; i++) free_cb(array->Elements[i]); } free(array->Elements); free(array); }
void free_Transition_list(Transition* t,void(*free_elag_tag)(symbol_t*),Abstract_allocator prv_alloc) { Transition* tmp; while (t!=NULL) { tmp=t; t=t->next; if (free_elag_tag!=NULL && tmp->label!=NULL) { free_elag_tag(tmp->label); } free_cb(tmp,prv_alloc); } }
/** * Erase an element from an array. */ void _eglEraseArray(_EGLArray *array, EGLint i, void (*free_cb)(void *)) { if (free_cb) free_cb(array->Elements[i]); if (i < array->Size - 1) { memmove(&array->Elements[i], &array->Elements[i + 1], (array->Size - i - 1) * sizeof(array->Elements[0])); } array->Size--; }
/** * Frees a string_hash_tree transition list. */ void free_string_hash_tree_transition(struct string_hash_tree_transition* t,int free_tree_node_struct,int free_tree_transition_struct,struct string_hash* s) { struct string_hash_tree_transition* tmp; while (t!=NULL) { free_arbre_hash(t->node,free_tree_node_struct,free_tree_transition_struct,s); tmp=t; t=t->next; if (free_tree_transition_struct) { free_cb(tmp,s->allocator_tree_transition); } } }
void free_circuit() { int i; struct s_linked_vptr *p_io_removed; /* Free netlist reference tables for nets */ free(clb_to_vpack_net_mapping); free(vpack_to_clb_net_mapping); clb_to_vpack_net_mapping = NULL; vpack_to_clb_net_mapping = NULL; /* Free logical blocks and nets */ if (logical_block != NULL) { free_logical_blocks(); free_logical_nets(); } if (clb_net != NULL) { for (i = 0; i < num_nets; i++) { free(clb_net[i].name); free(clb_net[i].node_block); free(clb_net[i].node_block_pin); free(clb_net[i].node_block_port); } } free(clb_net); clb_net = NULL; if (block != NULL) { for (i = 0; i < num_blocks; i++) { if (block[i].pb != NULL) { free_cb(block[i].pb); free(block[i].pb); } free(block[i].nets); free(block[i].name); } } free(block); block = NULL; free(blif_circuit_name); free(default_output_name); blif_circuit_name = NULL; p_io_removed = circuit_p_io_removed; while (p_io_removed != NULL) { circuit_p_io_removed = p_io_removed->next; free(p_io_removed->data_vptr); free(p_io_removed); p_io_removed = circuit_p_io_removed; } }
void RingList_free(RingList self, void (*free_cb)(void*)) { if(free_cb == NULL) { free_cb = free; } size_t head = self->head; for(size_t i = 0; i < self->len; ++i) { free_cb(self->zone[head++]); head = head & (self->cap - 1); } self->head = 0; self->tail = 0; self->len = 0; }
void hash_table_free(hash_table_t *ht, void (*free_cb)(void* data)) { int node_free_cb(void *data, void *cbarg) { if (free_cb != NULL) { free_cb(data); } return hash_table_foreach_delete; } hash_table_foreach( ht, node_free_cb, NULL); free(ht->nodes); free(ht); }
void DLinkList_free(DLinkList self, void (*free_cb)(void*)) { DLink p = self->list; DLink temp; for(size_t i = 0; i < self->len; ++i) { temp = p; p = p->next; if(free_cb == NULL) { free(temp); } else { free_cb(temp); } } self->list = NULL; self->len = 0; }
/** * Frees all the dictionary graph whose root is 'a'. */ void free_dictionary_node(struct dictionary_node* a,Abstract_allocator prv_alloc) { if (a==NULL) return; if (get_allocator_cb_flag(prv_alloc) & AllocatorGetFlagAutoFreePresent) return; if (a->incoming>1) { /* We don't free a state that is still pointed by someone else * in order to avoid double freeing problems. */ (a->incoming)--; return; } free_list_int(a->single_INF_code_list,prv_alloc); free_dictionary_node_transition(a->trans,prv_alloc); free_cb(a,prv_alloc); }
int ep_filter (const char **names, const char *signal, ep_decision_cb cb, void *user_data) { struct cb_data *data = calloc(1, sizeof(struct cb_data)); char **tmp = NULL; int names_len = 0, i; if (!data) goto failed; data->user_data = user_data; /* copy the names */ if (names) { for (tmp = (char **)names; *tmp != NULL; tmp++) { names_len++; } } data->decision_names = calloc(names_len+1, sizeof(char *)); if (!data->decision_names) goto failed; for (i = 0; i < names_len; i++) { data->decision_names[i] = strdup(names[i]); if (!data->decision_names[i]) goto failed; } data->signal = strdup(signal); if (!data->signal) goto failed; data->cb = cb; if (!ep_list_append(&cb_list, data)) goto failed; return 1; failed: free_cb(data); return 0; }
static void list_destroy_tagged_value_internal(tagged_value_t *tval, void (*free_cb)(void *v)) { if(tval) { free(tval->tag); if(tval->value) { if(tval->type == TV_TYPE_LIST) list_destroy((linked_list_t *)tval->value); else if (free_cb) free_cb(tval->value); else if (tval->vlen) free(tval->value); } free(tval); } }