diff options
| author | markus <> | 2003-11-11 21:21:30 +0000 |
|---|---|---|
| committer | markus <> | 2003-11-11 21:21:30 +0000 |
| commit | 9c1aa44a1eacea897c0432e796b205b8484ff4d2 (patch) | |
| tree | 5dcca7a2baa0fb63d6886729918ea26b68578561 /src/lib/libcrypto/err/err.c | |
| parent | 1c98a87f0daac81245653c227eb2f2508a22a965 (diff) | |
| download | openbsd-9c1aa44a1eacea897c0432e796b205b8484ff4d2.tar.gz openbsd-9c1aa44a1eacea897c0432e796b205b8484ff4d2.tar.bz2 openbsd-9c1aa44a1eacea897c0432e796b205b8484ff4d2.zip | |
import 0.9.7c
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/err/err.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c index b873270c04..633a1addfe 100644 --- a/src/lib/libcrypto/err/err.c +++ b/src/lib/libcrypto/err/err.c | |||
| @@ -225,6 +225,7 @@ struct st_ERR_FNS | |||
| 225 | ERR_STRING_DATA *(*cb_err_del_item)(ERR_STRING_DATA *); | 225 | ERR_STRING_DATA *(*cb_err_del_item)(ERR_STRING_DATA *); |
| 226 | /* Works on the "thread_hash" error-state table */ | 226 | /* Works on the "thread_hash" error-state table */ |
| 227 | LHASH *(*cb_thread_get)(int create); | 227 | LHASH *(*cb_thread_get)(int create); |
| 228 | void (*cb_thread_release)(LHASH **hash); | ||
| 228 | ERR_STATE *(*cb_thread_get_item)(const ERR_STATE *); | 229 | ERR_STATE *(*cb_thread_get_item)(const ERR_STATE *); |
| 229 | ERR_STATE *(*cb_thread_set_item)(ERR_STATE *); | 230 | ERR_STATE *(*cb_thread_set_item)(ERR_STATE *); |
| 230 | void (*cb_thread_del_item)(const ERR_STATE *); | 231 | void (*cb_thread_del_item)(const ERR_STATE *); |
| @@ -239,6 +240,7 @@ static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *); | |||
| 239 | static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *); | 240 | static ERR_STRING_DATA *int_err_set_item(ERR_STRING_DATA *); |
| 240 | static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *); | 241 | static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *); |
| 241 | static LHASH *int_thread_get(int create); | 242 | static LHASH *int_thread_get(int create); |
| 243 | static void int_thread_release(LHASH **hash); | ||
| 242 | static ERR_STATE *int_thread_get_item(const ERR_STATE *); | 244 | static ERR_STATE *int_thread_get_item(const ERR_STATE *); |
| 243 | static ERR_STATE *int_thread_set_item(ERR_STATE *); | 245 | static ERR_STATE *int_thread_set_item(ERR_STATE *); |
| 244 | static void int_thread_del_item(const ERR_STATE *); | 246 | static void int_thread_del_item(const ERR_STATE *); |
| @@ -252,6 +254,7 @@ static const ERR_FNS err_defaults = | |||
| 252 | int_err_set_item, | 254 | int_err_set_item, |
| 253 | int_err_del_item, | 255 | int_err_del_item, |
| 254 | int_thread_get, | 256 | int_thread_get, |
| 257 | int_thread_release, | ||
| 255 | int_thread_get_item, | 258 | int_thread_get_item, |
| 256 | int_thread_set_item, | 259 | int_thread_set_item, |
| 257 | int_thread_del_item, | 260 | int_thread_del_item, |
| @@ -271,6 +274,7 @@ static const ERR_FNS *err_fns = NULL; | |||
| 271 | * and state in the loading application. */ | 274 | * and state in the loading application. */ |
| 272 | static LHASH *int_error_hash = NULL; | 275 | static LHASH *int_error_hash = NULL; |
| 273 | static LHASH *int_thread_hash = NULL; | 276 | static LHASH *int_thread_hash = NULL; |
| 277 | static int int_thread_hash_references = 0; | ||
| 274 | static int int_err_library_number= ERR_LIB_USER; | 278 | static int int_err_library_number= ERR_LIB_USER; |
| 275 | 279 | ||
| 276 | /* Internal function that checks whether "err_fns" is set and if not, sets it to | 280 | /* Internal function that checks whether "err_fns" is set and if not, sets it to |
| @@ -417,11 +421,37 @@ static LHASH *int_thread_get(int create) | |||
| 417 | CRYPTO_pop_info(); | 421 | CRYPTO_pop_info(); |
| 418 | } | 422 | } |
| 419 | if (int_thread_hash) | 423 | if (int_thread_hash) |
| 424 | { | ||
| 425 | int_thread_hash_references++; | ||
| 420 | ret = int_thread_hash; | 426 | ret = int_thread_hash; |
| 427 | } | ||
| 421 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | 428 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); |
| 422 | return ret; | 429 | return ret; |
| 423 | } | 430 | } |
| 424 | 431 | ||
| 432 | static void int_thread_release(LHASH **hash) | ||
| 433 | { | ||
| 434 | int i; | ||
| 435 | |||
| 436 | if (hash == NULL || *hash == NULL) | ||
| 437 | return; | ||
| 438 | |||
| 439 | i = CRYPTO_add(&int_thread_hash_references, -1, CRYPTO_LOCK_ERR); | ||
| 440 | |||
| 441 | #ifdef REF_PRINT | ||
| 442 | fprintf(stderr,"%4d:%s\n",int_thread_hash_references,"ERR"); | ||
| 443 | #endif | ||
| 444 | if (i > 0) return; | ||
| 445 | #ifdef REF_CHECK | ||
| 446 | if (i < 0) | ||
| 447 | { | ||
| 448 | fprintf(stderr,"int_thread_release, bad reference count\n"); | ||
| 449 | abort(); /* ok */ | ||
| 450 | } | ||
| 451 | #endif | ||
| 452 | *hash = NULL; | ||
| 453 | } | ||
| 454 | |||
| 425 | static ERR_STATE *int_thread_get_item(const ERR_STATE *d) | 455 | static ERR_STATE *int_thread_get_item(const ERR_STATE *d) |
| 426 | { | 456 | { |
| 427 | ERR_STATE *p; | 457 | ERR_STATE *p; |
| @@ -436,6 +466,7 @@ static ERR_STATE *int_thread_get_item(const ERR_STATE *d) | |||
| 436 | p = (ERR_STATE *)lh_retrieve(hash, d); | 466 | p = (ERR_STATE *)lh_retrieve(hash, d); |
| 437 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR); | 467 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR); |
| 438 | 468 | ||
| 469 | ERRFN(thread_release)(&hash); | ||
| 439 | return p; | 470 | return p; |
| 440 | } | 471 | } |
| 441 | 472 | ||
| @@ -453,6 +484,7 @@ static ERR_STATE *int_thread_set_item(ERR_STATE *d) | |||
| 453 | p = (ERR_STATE *)lh_insert(hash, d); | 484 | p = (ERR_STATE *)lh_insert(hash, d); |
| 454 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | 485 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); |
| 455 | 486 | ||
| 487 | ERRFN(thread_release)(&hash); | ||
| 456 | return p; | 488 | return p; |
| 457 | } | 489 | } |
| 458 | 490 | ||
| @@ -469,13 +501,15 @@ static void int_thread_del_item(const ERR_STATE *d) | |||
| 469 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | 501 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); |
| 470 | p = (ERR_STATE *)lh_delete(hash, d); | 502 | p = (ERR_STATE *)lh_delete(hash, d); |
| 471 | /* make sure we don't leak memory */ | 503 | /* make sure we don't leak memory */ |
| 472 | if (int_thread_hash && (lh_num_items(int_thread_hash) == 0)) | 504 | if (int_thread_hash_references == 1 |
| 505 | && int_thread_hash && (lh_num_items(int_thread_hash) == 0)) | ||
| 473 | { | 506 | { |
| 474 | lh_free(int_thread_hash); | 507 | lh_free(int_thread_hash); |
| 475 | int_thread_hash = NULL; | 508 | int_thread_hash = NULL; |
| 476 | } | 509 | } |
| 477 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | 510 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); |
| 478 | 511 | ||
| 512 | ERRFN(thread_release)(&hash); | ||
| 479 | if (p) | 513 | if (p) |
| 480 | ERR_STATE_free(p); | 514 | ERR_STATE_free(p); |
| 481 | } | 515 | } |
| @@ -845,6 +879,12 @@ LHASH *ERR_get_err_state_table(void) | |||
| 845 | return ERRFN(thread_get)(0); | 879 | return ERRFN(thread_get)(0); |
| 846 | } | 880 | } |
| 847 | 881 | ||
| 882 | void ERR_release_err_state_table(LHASH **hash) | ||
| 883 | { | ||
| 884 | err_fns_check(); | ||
| 885 | ERRFN(thread_release)(hash); | ||
| 886 | } | ||
| 887 | |||
| 848 | const char *ERR_lib_error_string(unsigned long e) | 888 | const char *ERR_lib_error_string(unsigned long e) |
| 849 | { | 889 | { |
| 850 | ERR_STRING_DATA d,*p; | 890 | ERR_STRING_DATA d,*p; |
