void CRYPTO_destroy_dynlockid(int i) { CRYPTO_dynlock *pointer = NULL; if (i) i = -i - 1; if (dynlock_destroy_callback == NULL) return; CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK); if (dyn_locks == NULL || i >= sk_CRYPTO_dynlock_num(dyn_locks)) { CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); return; } pointer = sk_CRYPTO_dynlock_value(dyn_locks, i); if (pointer != NULL) { --pointer->references; #ifdef REF_DEBUG if (pointer->references < 0) { OPENSSL_showfatal("CRYPTO_destroy_dynlockid, bad reference count\n"); abort(); } else #endif if (pointer->references <= 0) { (void)sk_CRYPTO_dynlock_set(dyn_locks, i, NULL); } else pointer = NULL; } CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); if (pointer) { dynlock_destroy_callback(pointer->data, OPENSSL_FILE, OPENSSL_LINE); OPENSSL_free(pointer); } }
int CRYPTO_get_new_dynlockid(void) { int i = 0; CRYPTO_dynlock *pointer = NULL; if (dynlock_create_callback == NULL) { CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK); return(0); } CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK); if ((dyn_locks == NULL) && ((dyn_locks=sk_CRYPTO_dynlock_new_null()) == NULL)) { CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE); return(0); } CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); pointer = (CRYPTO_dynlock *)OPENSSL_malloc(sizeof(CRYPTO_dynlock)); if (pointer == NULL) { CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE); return(0); } pointer->references = 1; pointer->data = dynlock_create_callback(__FILE__,__LINE__); if (pointer->data == NULL) { OPENSSL_free(pointer); CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID,ERR_R_MALLOC_FAILURE); return(0); } CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK); /* First, try to find an existing empty slot */ i=sk_CRYPTO_dynlock_find(dyn_locks,NULL); /* If there was none, push, thereby creating a new one */ if (i == -1) /* Since sk_push() returns the number of items on the stack, not the location of the pushed item, we need to transform the returned number into a position, by decreasing it. */ i=sk_CRYPTO_dynlock_push(dyn_locks,pointer) - 1; else /* If we found a place with a NULL pointer, put our pointer in it. */ (void)sk_CRYPTO_dynlock_set(dyn_locks,i,pointer); CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); if (i == -1) { dynlock_destroy_callback(pointer->data,__FILE__,__LINE__); OPENSSL_free(pointer); } else i += 1; /* to avoid 0 */ return -i; }
void CRYPTO_destroy_dynlockid(int i) { CRYPTO_dynlock *pointer = NULL; if (i) i = -i-1; if (dynlock_destroy_callback == NULL) return; CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK); if (dyn_locks == NULL || i >= sk_CRYPTO_dynlock_num(dyn_locks)) { CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); return; } pointer = sk_CRYPTO_dynlock_value(dyn_locks, i); if (pointer != NULL) { --pointer->references; #ifdef REF_CHECK if (pointer->references < 0) { TINYCLR_SSL_FPRINTF(OPENSSL_TYPE__FILE_STDERR,"CRYPTO_destroy_dynlockid, bad reference count\n"); TINYCLR_SSL_ABORT(); } else #endif if (pointer->references <= 0) { (void)sk_CRYPTO_dynlock_set(dyn_locks, i, NULL); } else pointer = NULL; } CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); if (pointer) { dynlock_destroy_callback(pointer->data,__FILE__,__LINE__); OPENSSL_free(pointer); } }
void CRYPTO_destroy_dynlockid(int i) { CRYPTO_dynlock *pointer = NULL; if (i) i = -i-1; if (dynlock_destroy_callback == NULL) return; CRYPTO_w_lock(CRYPTO_LOCK_DYNLOCK); if (dyn_locks == NULL || i >= sk_CRYPTO_dynlock_num(dyn_locks)) { CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); return; } pointer = sk_CRYPTO_dynlock_value(dyn_locks, i); if (pointer != NULL) { --pointer->references; #ifdef REF_CHECK if (pointer->references < 0) { fprintf(stderr,"CRYPTO_destroy_dynlockid, bad reference count\n"); abort(); } else #endif if (pointer->references <= 0) { sk_CRYPTO_dynlock_set(dyn_locks, i, NULL); } else pointer = NULL; } CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); if (pointer) { dynlock_destroy_callback(pointer->data,__FILE__,__LINE__); OPENSSL_free(pointer); } }