int OBJ_NAME_remove(const char *name, int type) { OBJ_NAME on,*ret; if (names_lh == NULL) return(0); type&= ~OBJ_NAME_ALIAS; on.name=name; on.type=type; ret=(OBJ_NAME *)lh_delete(names_lh,&on); if (ret != NULL) { /* free things */ if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type)) { /* XXX: I'm not sure I understand why the free * function should get three arguments... * -- Richard Levitte */ sk_NAME_FUNCS_value(name_funcs_stack,ret->type) ->free_func(ret->name,ret->type,ret->data); } OPENSSL_free(ret); return(1); } else return(0); }
void CRYPTO_dbg_free(void *addr, int before_p) { MEM m,*mp; switch(before_p) { case 0: if (addr == NULL) break; if (is_MemCheck_on() && (mh != NULL)) { MemCheck_off(); /* make sure we hold MALLOC2 lock */ m.addr=addr; mp=(MEM *)lh_delete(mh,(char *)&m); if (mp != NULL) { #ifdef LEVITTE_DEBUG_MEM fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] - 0x%p (%d)\n", mp->order, mp->addr, mp->num); #endif if (mp->app_info != NULL) app_info_free(mp->app_info); OPENSSL_free(mp); } MemCheck_on(); /* release MALLOC2 lock * if num_disabled drops to 0 */ } break; case 1: break; } }
static void int_thread_del_item(const ERR_STATE *d) { ERR_STATE *p; LHASH *hash; err_fns_check(); hash = ERRFN(thread_get)(0); if (!hash) return; CRYPTO_w_lock(CRYPTO_LOCK_ERR); p = (ERR_STATE *)lh_delete(hash, d); /* make sure we don't leak memory */ if (int_thread_hash_references == 1 && int_thread_hash && (lh_num_items(int_thread_hash) == 0)) { lh_free(int_thread_hash); int_thread_hash = NULL; } CRYPTO_w_unlock(CRYPTO_LOCK_ERR); ERRFN(thread_release)(&hash); if (p) ERR_STATE_free(p); }
void CRYPTO_dbg_realloc(void *addr1, void *addr2, int num, const char *file, int line, int before_p) { MEM m,*mp; #ifdef LEVITTE_DEBUG_MEM fprintf(stderr, "LEVITTE_DEBUG_MEM: --> CRYPTO_dbg_malloc(addr1 = %p, addr2 = %p, num = %d, file = \"%s\", line = %d, before_p = %d)\n", addr1, addr2, num, file, line, before_p); #endif switch(before_p) { case 0: break; case 1: if (addr2 == NULL) break; if (addr1 == NULL) { CRYPTO_dbg_malloc(addr2, num, file, line, 128 | before_p); break; } if (is_MemCheck_on()) { MemCheck_off(); /* make sure we hold MALLOC2 lock */ m.addr=addr1; mp=(MEM *)lh_delete(mh,(char *)&m); if (mp != NULL) { #ifdef LEVITTE_DEBUG_MEM fprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] * 0x%p (%d) -> 0x%p (%d)\n", mp->order, mp->addr, mp->num, addr2, num); #endif mp->addr=addr2; mp->num=num; lh_insert(mh,(char *)mp); } MemCheck_on(); /* release MALLOC2 lock * if num_disabled drops to 0 */ } break; } return; }
void ERR_remove_state(unsigned long pid) { ERR_STATE *p,tmp; if (thread_hash == NULL) return; if (pid == 0) pid=(unsigned long)CRYPTO_thread_id(); tmp.pid=pid; CRYPTO_w_lock(CRYPTO_LOCK_ERR); p=(ERR_STATE *)lh_delete(thread_hash,&tmp); CRYPTO_w_unlock(CRYPTO_LOCK_ERR); if (p != NULL) ERR_STATE_free(p); }
static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *d) { ERR_STRING_DATA *p; LHASH *hash; err_fns_check(); hash = ERRFN(err_get)(0); if (!hash) return NULL; CRYPTO_w_lock(CRYPTO_LOCK_ERR); p = (ERR_STRING_DATA *)lh_delete(hash, d); CRYPTO_w_unlock(CRYPTO_LOCK_ERR); return p; }
static APP_INFO *pop_info(void) { APP_INFO tmp; APP_INFO *ret = NULL; if (amih != NULL) { tmp.thread=CRYPTO_thread_id(); if ((ret=(APP_INFO *)lh_delete(amih,&tmp)) != NULL) { APP_INFO *next=ret->next; if (next != NULL) { next->references++; lh_insert(amih,(char *)next); } #ifdef LEVITTE_DEBUG_MEM if (ret->thread != tmp.thread) { fprintf(stderr, "pop_info(): deleted info has other thread ID (%lu) than the current thread (%lu)!!!!\n", ret->thread, tmp.thread); abort(); } #endif if (--(ret->references) <= 0) { ret->next = NULL; if (next != NULL) next->references--; OPENSSL_free(ret); } } } return(ret); }
void ERR_remove_state(unsigned long pid) { ERR_STATE *p = NULL,tmp; if (thread_hash == NULL) return; if (pid == 0) pid=(unsigned long)CRYPTO_thread_id(); tmp.pid=pid; CRYPTO_w_lock(CRYPTO_LOCK_ERR); if (thread_hash) { p=(ERR_STATE *)lh_delete(thread_hash,&tmp); if (lh_num_items(thread_hash) == 0) { /* make sure we don't leak memory */ lh_free(thread_hash); thread_hash = NULL; } } CRYPTO_w_unlock(CRYPTO_LOCK_ERR); if (p != NULL) ERR_STATE_free(p); }
int main(int argc, char **argv) { _LHASH *lh; struct dummy_lhash dummy_lh = {NULL}; unsigned i; CRYPTO_library_init(); lh = lh_new(NULL, NULL); if (lh == NULL) { return 1; } for (i = 0; i < 100000; i++) { unsigned action; char *s, *s1, *s2; if (dummy_lh_num_items(&dummy_lh) != lh_num_items(lh)) { fprintf(stderr, "Length mismatch\n"); return 1; } action = rand() % 3; switch (action) { case 0: s = rand_string(); s1 = (char *)lh_retrieve(lh, s); s2 = dummy_lh_retrieve(&dummy_lh, s); if (s1 != NULL && (s2 == NULL || strcmp(s1, s2) != 0)) { fprintf(stderr, "lh_retrieve failure\n"); abort(); } free(s); break; case 1: s = rand_string(); lh_insert(lh, (void **)&s1, s); dummy_lh_insert(&dummy_lh, &s2, strdup(s)); if (s1 != NULL && (s2 == NULL || strcmp(s1, s2) != 0)) { fprintf(stderr, "lh_insert failure\n"); abort(); } if (s1) { free(s1); } if (s2) { free(s2); } break; case 2: s = rand_string(); s1 = lh_delete(lh, s); s2 = dummy_lh_delete(&dummy_lh, s); if (s1 != NULL && (s2 == NULL || strcmp(s1, s2) != 0)) { fprintf(stderr, "lh_insert failure\n"); abort(); } if (s1) { free(s1); } if (s2) { free(s2); } free(s); break; default: abort(); } } lh_doall(lh, free); lh_free(lh); dummy_lh_free(&dummy_lh); printf("PASS\n"); return 0; }
data = lh_get(table, key_2); assert(data); assert( data_2 == *data ); assert( lh_insert(table, key_3, &data_3) ); assert( 3 == lh_nelems(table) ); data = lh_get(table, key_3); assert(data); assert( data_3 == *data ); puts("testing delete"); puts("one delete"); data = lh_delete(table, key_1); assert(data); assert(*data == data_1); assert( 2 == lh_nelems(table) ); /* should not be able to re-delete */ data = lh_delete(table, key_1); assert(! data); puts("two delete"); data = lh_delete(table, key_3); assert(data); assert(*data == data_3); assert( 1 == lh_nelems(table) );