| 356 | } |
| 357 | |
| 358 | static void init() { |
| 359 | static int once = 1; |
| 360 | if (once) { |
| 361 | once = 0; |
| 362 | pthread_mutexattr_t mattr; |
| 363 | pthread_mutexattr_init(&mattr); |
| 364 | pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE); |
| 365 | Pthread_mutex_init(&lk, &mattr); |
| 366 | Pthread_key_create(&threadk, thread_done); |
| 367 | calls = hash_setalloc_init_user(call_hashfunc, call_cmpfunc, dl_malloc, dl_free, 0, sizeof(int)); |
| 368 | listc_init(&blocks, offsetof(struct memblock, alnk)); |
| 369 | init_symtab(); |
| 370 | in_init = 0; |
| 371 | /* if the debug variable is not set, the malloc/etc. code continues to call real malloc */ |
| 372 | |
| 373 | memdebug_out = fopen("memdebug.out", "w"); |
| 374 | setbuf(memdebug_out, NULL); |
| 375 | |
| 376 | atexit(dump_callers_at_exit); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | void *malloc(size_t size) { |
| 381 | struct call *c; |