void *CRYPTO_realloc_clean(void *str, int old_len, int num, const char *file, int line) { void *ret = NULL; if (str == NULL) return CRYPTO_malloc(num, file, line); if (num <= 0) return NULL; /* We don't support shrinking the buffer. Note the memcpy that copies * |old_len| bytes to the new buffer, below. */ if (num < old_len) return NULL; if (realloc_debug_func != NULL) realloc_debug_func(str, NULL, num, file, line, 0); ret=malloc_ex_func(num,file,line); if(ret) { memcpy(ret,str,old_len); OPENSSL_cleanse(str,old_len); free_func(str); } #ifdef LEVITTE_DEBUG_MEM fprintf(stderr, "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n", str, ret, num); #endif if (realloc_debug_func != NULL) realloc_debug_func(str, ret, num, file, line, 1); return ret; }
void *CRYPTO_realloc_clean(void *str, int old_len, int num, const char *file, int line) { void *ret = NULL; if (str == NULL) return CRYPTO_malloc(num, file, line); if (num <= 0) return NULL; if (realloc_debug_func != NULL) realloc_debug_func(str, NULL, num, file, line, 0); ret=malloc_ex_func(num,file,line); if(ret) { memcpy(ret,str,old_len); OPENSSL_cleanse(str,old_len); free_func(str); } #ifdef LEVITTE_DEBUG_MEM fprintf(stderr, "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n", str, ret, num); #endif if (realloc_debug_func != NULL) realloc_debug_func(str, ret, num, file, line, 1); return ret; }
/* Pre/unrolls basic block and optimizes it */ cuc_timings * preunroll_bb (char *bb_filename, cuc_func * f, cuc_timings * timings, int b, int i, int j) { cuc_func *func; cucdebug (2, "BB%i unroll %i times preroll %i times\n", b, j, i); log ("BB%i unroll %i times preroll %i times\n", b, j, i); func = preunroll_loop (f, b, i, j, bb_filename); if (cuc_debug >= 2) print_cuc_bb (func, "AFTER_PREUNROLL"); cuc_optimize (func); analyse_timings (func, timings); cucdebug (2, "new_time = %i, old_time = %i, size = %f\n", timings->new_time, func->orig_time, timings->size); log ("new time = %icyc, old_time = %icyc, size = %.0f gates\n", timings->new_time, func->orig_time, timings->size); //output_verilog (func, argv[1]); free_func (func); timings->b = b; timings->unroll = j; timings->preroll = i; timings->nshared = 0; return timings; }
/* * Post 1.0.1 sk function "deep_copy". For the moment we simply make * these take void * and use them directly without a glorious blob of * obfuscating macros of dubious value in front of them. All this in * preparation for a rototilling of safestack.h (likely inspired by * this). */ static void * sk_deep_copy(void *sk_void, void *copy_func_void, void *free_func_void) { _STACK *sk = sk_void; void *(*copy_func)(void *) = copy_func_void; void (*free_func)(void *) = free_func_void; _STACK *ret = sk_dup(sk); size_t i; if (ret == NULL) return NULL; for (i = 0; i < ret->num; i++) { if (ret->data[i] == NULL) continue; ret->data[i] = copy_func(ret->data[i]); if (ret->data[i] == NULL) { size_t j; for (j = 0; j < i; j++) { if (ret->data[j] != NULL) free_func(ret->data[j]); } sk_free(ret); return NULL; } } return ret; }
void free_all_funcs() { int x; for (x=0; x<num_funcs; x++) free_func(funcs[x]); free(funcs); }
_STACK *sk_deep_copy(const _STACK *sk, void *(*copy_func)(void *), void (*free_func)(void *)) { _STACK *ret = sk_dup(sk); if (ret == NULL) { return NULL; } for (size_t i = 0; i < ret->num; i++) { if (ret->data[i] == NULL) { continue; } ret->data[i] = copy_func(ret->data[i]); if (ret->data[i] == NULL) { for (size_t j = 0; j < i; j++) { if (ret->data[j] != NULL) { free_func(ret->data[j]); } } sk_free(ret); return NULL; } } return ret; }
void ff_dirac_schro_queue_free (FfmpegDiracSchroQueue *queue, void (*free_func)(void *)) { while (queue->p_head) { free_func( ff_dirac_schro_queue_pop(queue) ); } }
cbdataUnlock(const void *p) #endif { cbdata *c; FREE *free_func; if (p == NULL) return; c = (cbdata *) (((char *) p) - OFFSET_OF(cbdata, data)); assert(c->y == c); debug(45, 3) ("cbdataUnlock: %p\n", p); assert(c != NULL); assert(c->locks > 0); c->locks--; #if CBDATA_DEBUG c->file = file; c->line = line; #endif if (c->valid || c->locks) return; cbdataCount--; debug(45, 3) ("cbdataUnlock: Freeing %p\n", p); free_func = cbdata_index[c->type].free_func; if (free_func) free_func((void *) p); memPoolFree(cbdata_index[c->type].pool, c); }
/** Destroys one ::xtele_list element. * @param list The ::xtele_list element to destroy * @param free_func The function called to destroy the data of the element. */ void xtele_list_destroy_one(xtele_list* list, void (*free_func) (void*) ) { if(list) { if(free_func) free_func(list->data); free(list); } }
_STACK *sk_deep_copy(_STACK *sk, void *(*copy_func) (void *), void (*free_func) (void *)) { _STACK *ret; int i; if ((ret = OPENSSL_malloc(sizeof(_STACK))) == NULL) return ret; ret->comp = sk->comp; ret->sorted = sk->sorted; ret->num = sk->num; ret->num_alloc = sk->num > MIN_NODES ? sk->num : MIN_NODES; ret->data = OPENSSL_malloc(sizeof(*ret->data) * ret->num_alloc); if (ret->data == NULL) { OPENSSL_free(ret); return NULL; } for (i = 0; i < ret->num_alloc; i++) ret->data[i] = NULL; for (i = 0; i < ret->num; ++i) { if (sk->data[i] == NULL) continue; if ((ret->data[i] = copy_func(sk->data[i])) == NULL) { while (--i >= 0) if (ret->data[i] != NULL) free_func(ret->data[i]); sk_free(ret); return NULL; } } return ret; }
void aioWrite(int fd, int offset, char *bufp, int len, AIOCB * callback, void *callback_data, FREE * free_func) { aio_ctrl_t *ctrlp; int seekmode; assert(initialised); aio_counts.write++; for (ctrlp = used_list; ctrlp != NULL; ctrlp = ctrlp->next) if (ctrlp->fd == fd) break; if (ctrlp != NULL) { debug(32, 2) ("aioWrite: EWOULDBLOCK\n"); errno = EWOULDBLOCK; if (callback) (callback) (fd, callback_data, -1, errno); free_func(bufp); return; } ctrlp = memPoolAlloc(aio_ctrl_pool); ctrlp->fd = fd; ctrlp->done_handler = callback; ctrlp->done_handler_data = callback_data; ctrlp->operation = _AIO_WRITE; if (offset >= 0) seekmode = SEEK_SET; else { seekmode = SEEK_END; offset = 0; } cbdataLock(callback_data); if (aio_write(fd, bufp, len, offset, seekmode, &ctrlp->result) < 0) { if (errno == ENOMEM || errno == EAGAIN || errno == EINVAL) errno = EWOULDBLOCK; if (callback) (callback) (fd, callback_data, -1, errno); cbdataUnlock(callback_data); memPoolFree(aio_ctrl_pool, ctrlp); } else { ctrlp->next = used_list; used_list = ctrlp; } /* * aio_write copies the buffer so we can free it here */ free_func(bufp); } /* aioWrite */
void stack_destroy_traverse(struct stack_node *n, void (*free_func)(void *)) { if (n->next) { stack_destroy_traverse(n->next, free_func); } free_func(n->value); free(n); }
void free_func_chain(nasl_func* f) { if (f == NULL) return; free_func_chain(f->next_func); free_func(f); }
void list_destroy(node* n, void (*free_func)(void* data)) { while(n) { node* temp = n; free_func(temp->data); n = temp->next; free(temp); } }
int main(int ac, char** av) { instr_t* imem; int imem_size; int yyparse(); int yylex_destroy(); progname = av[0]; output = stdout; init_func(); init_instr(); init_stmt(); init_sim(); params(ac, av); if (yyin == NULL) { warning("no input file"); exit(0); } if (cfg_fp == NULL) yyparse(); fclose(yyin); yylex_destroy(); opt(); if (cfg_fp != NULL) exit(0); imem = stmt2instr(&imem_size); free_func(); deinit_symtab(); deinit_sym(); set_dmem_size(100000); set_imem(imem, imem_size); set_regs(32); run(); print_stats(); free_sim(); if (output != NULL) fclose(output); if (yyin != NULL) fclose(yyin); return 0; }
static inline void _eina_matrixsparse_cell_free(Eina_Matrixsparse_Cell *c, void (*free_func)(void *, void *), void *user_data) { if (free_func) free_func(user_data, c->data); EINA_MAGIC_SET(c, EINA_MAGIC_NONE); eina_mempool_free(_eina_matrixsparse_cell_mp, c); }
gint g_list_free_all_node(GList *list, void (*free_func)(gpointer)) { while (list != NULL) { free_func(list->data); list = g_list_next(list); } return 0; }
int list_delete(t_list *list, t_elem *self, void (*free_func)(void *data)) { list_remove(list, self); free_func(self->data); if (list->head == NULL) return (1); return (0); }
void b_slist_free_full(b_slist_t *l, void (*free_func)(void *ptr)) { while (l != NULL) { b_slist_t *tmp = l->next; free_func(l->data); free(l); l = tmp; } }
/** * @brief Remove and free all (key,val) couples from the hash store * * This function removes all (key,val) couples from the hashtable and * frees the stored data using the supplied function * * @param[in,out] ht The hashtable to be cleared of all entries * @param[in] free_func The function with which to free the contents * of each entry * * @return HASHTABLE_SUCCESS or errors */ hash_error_t hashtable_delall(struct hash_table *ht, int (*free_func)(struct gsh_buffdesc, struct gsh_buffdesc)) { /* Successive partition numbers */ uint32_t index = 0; for (index = 0; index < ht->parameter.index_size; index++) { /* The root of each successive partition */ struct rbt_head *root = &ht->partitions[index].rbt; /* Pointer to node in tree for removal */ struct rbt_node *cursor = NULL; PTHREAD_RWLOCK_wrlock(&ht->partitions[index].lock); /* Continue until there are no more entries in the red-black tree */ while ((cursor = RBT_LEFTMOST(root)) != NULL) { /* Pointer to the key and value descriptors for each successive entry */ struct hash_data *data = NULL; /* Aliased poitner to node, for freeing buffers after removal from tree */ struct rbt_node *holder = cursor; /* Buffer descriptor for key, as stored */ struct gsh_buffdesc key; /* Buffer descriptor for value, as stored */ struct gsh_buffdesc val; /* Return code from the free function. Zero on failure */ int rc = 0; RBT_UNLINK(root, cursor); data = RBT_OPAQ(holder); key = data->key; val = data->val; pool_free(ht->data_pool, data); pool_free(ht->node_pool, holder); --ht->partitions[index].count; rc = free_func(key, val); if (rc == 0) { PTHREAD_RWLOCK_unlock(&ht->partitions[index]. lock); return HASHTABLE_ERROR_DELALL_FAIL; } } PTHREAD_RWLOCK_unlock(&ht->partitions[index].lock); } return HASHTABLE_SUCCESS; }
void CRYPTO_free(void *str) { if (free_debug_func != NULL) free_debug_func(str, 0); #ifdef LEVITTE_DEBUG_MEM fprintf(stderr, "LEVITTE_DEBUG_MEM: < 0x%p\n", str); #endif free_func(str); if (free_debug_func != NULL) free_debug_func(NULL, 1); }
int darray_clear(darray_t *arr, FREE_FUNC) { for (long i = 0; i < arr->size; i++) { if (free_func) { free_func(&arr->data[i]); } arr->data[i] = NULL; } arr->size = 0; return 1; }
void CZhList::Free(void *(*free_func) (void*)) { void* element; while (!IsListEof(0)) { element = (void *) GetAt(0); RemoveAt(0); if (free_func != NULL) free_func(element); } }
void list_empty(t_list *list, void (*free_func)(void *data)) { t_elem *tmp; t_elem *next; for (tmp = list->head; tmp != NULL; tmp = next) { next = tmp->next; free_func(tmp->data); } list->head = list->tail = NULL; list->size = 0; }
void osip_list_special_free(osip_list_t * li, void (*free_func) (void *)) { void *element; if (li == NULL) return; while (!osip_list_eol(li, 0)) { element = (void *) osip_list_get(li, 0); osip_list_remove(li, 0); if (free_func != NULL) free_func(element); } }
/** * Retrieves a list with unique items from file. * * @filename: file to read items from * @func: function to parse a single line to item * @unique_func: function to decide if two items are equal * @free_func: function to free already converted item if this isn't unique * @max_items: maximum number of items that are returned, use 0 for * unlimited items */ GList *util_file_to_unique_list(const char *filename, Util_Content_Func func, GCompareFunc unique_func, GDestroyNotify free_func, unsigned int max_items) { GList *gl = NULL; /* yes, the whole file is read and wen possible don not need all the * lines, but this is easier to implement compared to reading the file * line wise from end to beginning */ char *line, **lines; void *value; int len, num_items = 0; /* return empty list if max items is 0 */ if (!max_items) { return gl; } lines = util_get_lines(filename); len = g_strv_length(lines); if (!len) { return gl; } /* begin with the last line of the file to make unique check easier - * every already existing item in the list is the latest, so we don't need * to remove items from the list which takes some time */ for (int i = len - 1; i >= 0; i--) { line = lines[i]; g_strstrip(line); if (!*line) { continue; } if ((value = func(line))) { /* if the value is already in list, free it and don't put it onto * the list */ if (g_list_find_custom(gl, value, unique_func)) { free_func(value); } else { gl = g_list_prepend(gl, value); /* skip the loop if we precessed max_items unique items */ if (++num_items >= max_items) { break; } } } } g_strfreev(lines); return gl; }
void storeDiskdWrite(SwapDir * SD, storeIOState * sio, char *buf, size_t size, squid_off_t offset, FREE * free_func) { int x; char *sbuf; int shm_offset; diskdstate_t *diskdstate = sio->fsstate; debug(79, 3) ("storeDiskdWrite: dirno %d, fileno %08X\n", SD->index, sio->swap_filen); assert(!diskdstate->flags.close_request); if (diskdstate->flags.close_request) { debug(79, 2) ("storeDiskWrite: closing, so ignore!\n"); free_func(buf); return; } if (!cbdataValid(sio)) { free_func(buf); return; } diskdstate->flags.writing = 1; sbuf = storeDiskdShmGet(SD, &shm_offset); xmemcpy(sbuf, buf, size); if (free_func) free_func(buf); x = storeDiskdSend(_MQD_WRITE, SD, diskdstate->id, sio, size, (off_t) offset, shm_offset); if (x < 0) { debug(79, 1) ("storeDiskdSend WRITE: %s\n", xstrerror()); storeDiskdShmPut(SD, shm_offset); storeDiskdIOCallback(sio, DISK_ERROR); } diskd_stats.write.ops++; }
gboolean cib_client_register_callback_full(cib_t *cib, int call_id, int timeout, gboolean only_success, void *user_data, const char *callback_name, void (*callback)(xmlNode *, int, int, xmlNode *, void *), void (*free_func)(void *)) { cib_callback_client_t *blob = NULL; if (call_id < 0) { if (only_success == FALSE) { callback(NULL, call_id, call_id, NULL, user_data); } else { crm_warn("CIB call failed: %s", pcmk_strerror(call_id)); } if (user_data && free_func) { free_func(user_data); } return FALSE; } blob = calloc(1, sizeof(cib_callback_client_t)); blob->id = callback_name; blob->only_success = only_success; blob->user_data = user_data; blob->callback = callback; blob->free_func = free_func; if (timeout > 0) { struct timer_rec_s *async_timer = NULL; async_timer = calloc(1, sizeof(struct timer_rec_s)); blob->timer = async_timer; async_timer->cib = cib; async_timer->call_id = call_id; async_timer->timeout = timeout * 1000; async_timer->ref = g_timeout_add(async_timer->timeout, cib_async_timeout_handler, async_timer); } crm_trace("Adding callback %s for call %d", callback_name, call_id); g_hash_table_insert(cib_op_callback_table, GINT_TO_POINTER(call_id), blob); return TRUE; }
void cogl_handle_unref (CoglHandle handle) { CoglHandleObject *obj = (CoglHandleObject *)handle; g_return_if_fail (handle != COGL_INVALID_HANDLE); g_return_if_fail (obj->ref_count > 0); if (--obj->ref_count < 1) { void (*free_func)(void *obj); COGL_HANDLE_DEBUG_FREE (obj); free_func = obj->klass->virt_free; free_func (obj); } }
void hashFreeItems(hash_table * hid, HASHFREE * free_func) { hash_link *l; hash_link **list; int i = 0; int j; list = xcalloc(hid->count, sizeof(hash_link *)); hash_first(hid); while ((l = hash_next(hid)) && i < hid->count) { *(list + i) = l; i++; } for (j = 0; j < i; j++) free_func(*(list + j)); xfree(list); }