crypto/dh/dh_lib.c:147: error: MEMORY_LEAK
  memory dynamically allocated by call to `CRYPTO_THREAD_lock_new()` at line 113, column 17 is not reachable after line 147, column 9.
Showing all 86 steps of the trace


crypto/dh/dh_lib.c:103:1: start of procedure DH_new_method()
101.   }
102.   
103. > DH *DH_new_method(ENGINE *engine)
104.   {
105.       DH *ret = OPENSSL_zalloc(sizeof(*ret));

crypto/dh/dh_lib.c:105:5: 
103.   DH *DH_new_method(ENGINE *engine)
104.   {
105. >     DH *ret = OPENSSL_zalloc(sizeof(*ret));
106.   
107.       if (ret == NULL) {

crypto/mem.c:146:1: start of procedure CRYPTO_zalloc()
  144.   }
  145.   
  146. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
  147.   {
  148.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:148:5: 
  146.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
  147.   {
  148. >     void *ret = CRYPTO_malloc(num, file, line);
  149.   
  150.       if (ret != NULL)

crypto/mem.c:119:1: start of procedure CRYPTO_malloc()
    117.   }
    118.   
    119. > void *CRYPTO_malloc(size_t num, const char *file, int line)
    120.   {
    121.       void *ret = NULL;

crypto/mem.c:121:5: 
    119.   void *CRYPTO_malloc(size_t num, const char *file, int line)
    120.   {
    121. >     void *ret = NULL;
    122.   
    123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:123:9: Taking false branch
    121.       void *ret = NULL;
    122.   
    123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                   ^
    124.           return malloc_impl(num, file, line);
    125.   

crypto/mem.c:126:9: Taking false branch
    124.           return malloc_impl(num, file, line);
    125.   
    126.       if (num <= 0)
                   ^
    127.           return NULL;
    128.   

crypto/mem.c:129:5: 
    127.           return NULL;
    128.   
    129. >     allow_customize = 0;
    130.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
    131.       if (call_malloc_debug) {

crypto/mem.c:139:5: 
    137.       }
    138.   #else
    139. >     osslargused(file); osslargused(line);
    140.       ret = malloc(num);
    141.   #endif

crypto/mem.c:139:24: 
    137.       }
    138.   #else
    139. >     osslargused(file); osslargused(line);
    140.       ret = malloc(num);
    141.   #endif

crypto/mem.c:140:5: 
    138.   #else
    139.       osslargused(file); osslargused(line);
    140. >     ret = malloc(num);
    141.   #endif
    142.   

crypto/mem.c:143:5: 
    141.   #endif
    142.   
    143. >     return ret;
    144.   }
    145.   

crypto/mem.c:144:1: return from a call to CRYPTO_malloc
    142.   
    143.       return ret;
    144. > }
    145.   
    146.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:150:9: Taking true branch
  148.       void *ret = CRYPTO_malloc(num, file, line);
  149.   
  150.       if (ret != NULL)
                 ^
  151.           memset(ret, 0, num);
  152.       return ret;

crypto/mem.c:151:9: 
  149.   
  150.       if (ret != NULL)
  151. >         memset(ret, 0, num);
  152.       return ret;
  153.   }

crypto/mem.c:152:5: 
  150.       if (ret != NULL)
  151.           memset(ret, 0, num);
  152. >     return ret;
  153.   }
  154.   

crypto/mem.c:153:1: return from a call to CRYPTO_zalloc
  151.           memset(ret, 0, num);
  152.       return ret;
  153. > }
  154.   
  155.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/dh/dh_lib.c:107:9: Taking false branch
105.       DH *ret = OPENSSL_zalloc(sizeof(*ret));
106.   
107.       if (ret == NULL) {
               ^
108.           DHerr(DH_F_DH_NEW_METHOD, ERR_R_MALLOC_FAILURE);
109.           return NULL;

crypto/dh/dh_lib.c:112:5: 
110.       }
111.   
112. >     ret->references = 1;
113.       ret->lock = CRYPTO_THREAD_lock_new();
114.       if (ret->lock == NULL) {

crypto/dh/dh_lib.c:113:5: 
111.   
112.       ret->references = 1;
113. >     ret->lock = CRYPTO_THREAD_lock_new();
114.       if (ret->lock == NULL) {
115.           OPENSSL_free(ret);

crypto/threads_pthread.c:55:1: start of procedure CRYPTO_THREAD_lock_new()
  53.   #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG) && !defined(OPENSSL_SYS_WINDOWS)
  54.   
  55. > CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
  56.   {
  57.       CRYPTO_RWLOCK *lock = OPENSSL_zalloc(sizeof(pthread_rwlock_t));

crypto/threads_pthread.c:57:5: 
  55.   CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
  56.   {
  57. >     CRYPTO_RWLOCK *lock = OPENSSL_zalloc(sizeof(pthread_rwlock_t));
  58.       if (lock == NULL)
  59.           return NULL;

crypto/mem.c:146:1: start of procedure CRYPTO_zalloc()
    144.   }
    145.   
    146. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    147.   {
    148.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:148:5: 
    146.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    147.   {
    148. >     void *ret = CRYPTO_malloc(num, file, line);
    149.   
    150.       if (ret != NULL)

crypto/mem.c:119:1: start of procedure CRYPTO_malloc()
      117.   }
      118.   
      119. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121.       void *ret = NULL;

crypto/mem.c:121:5: 
      119.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121. >     void *ret = NULL;
      122.   
      123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:123:9: Taking false branch
      121.       void *ret = NULL;
      122.   
      123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      124.           return malloc_impl(num, file, line);
      125.   

crypto/mem.c:126:9: Taking false branch
      124.           return malloc_impl(num, file, line);
      125.   
      126.       if (num <= 0)
                     ^
      127.           return NULL;
      128.   

crypto/mem.c:129:5: 
      127.           return NULL;
      128.   
      129. >     allow_customize = 0;
      130.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      131.       if (call_malloc_debug) {

crypto/mem.c:139:5: 
      137.       }
      138.   #else
      139. >     osslargused(file); osslargused(line);
      140.       ret = malloc(num);
      141.   #endif

crypto/mem.c:139:24: 
      137.       }
      138.   #else
      139. >     osslargused(file); osslargused(line);
      140.       ret = malloc(num);
      141.   #endif

crypto/mem.c:140:5: 
      138.   #else
      139.       osslargused(file); osslargused(line);
      140. >     ret = malloc(num);
      141.   #endif
      142.   

crypto/mem.c:143:5: 
      141.   #endif
      142.   
      143. >     return ret;
      144.   }
      145.   

crypto/mem.c:144:1: return from a call to CRYPTO_malloc
      142.   
      143.       return ret;
      144. > }
      145.   
      146.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:150:9: Taking true branch
    148.       void *ret = CRYPTO_malloc(num, file, line);
    149.   
    150.       if (ret != NULL)
                   ^
    151.           memset(ret, 0, num);
    152.       return ret;

crypto/mem.c:151:9: 
    149.   
    150.       if (ret != NULL)
    151. >         memset(ret, 0, num);
    152.       return ret;
    153.   }

crypto/mem.c:152:5: 
    150.       if (ret != NULL)
    151.           memset(ret, 0, num);
    152. >     return ret;
    153.   }
    154.   

crypto/mem.c:153:1: return from a call to CRYPTO_zalloc
    151.           memset(ret, 0, num);
    152.       return ret;
    153. > }
    154.   
    155.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/threads_pthread.c:58:9: Taking false branch
  56.   {
  57.       CRYPTO_RWLOCK *lock = OPENSSL_zalloc(sizeof(pthread_rwlock_t));
  58.       if (lock == NULL)
                ^
  59.           return NULL;
  60.   

crypto/threads_pthread.c:61:9: Taking false branch
  59.           return NULL;
  60.   
  61.       if (pthread_rwlock_init(lock, NULL) != 0) {
                ^
  62.           OPENSSL_free(lock);
  63.           return NULL;

crypto/threads_pthread.c:66:5: 
  64.       }
  65.   
  66. >     return lock;
  67.   }
  68.   

crypto/threads_pthread.c:67:1: return from a call to CRYPTO_THREAD_lock_new
  65.   
  66.       return lock;
  67. > }
  68.   
  69.   int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock)

crypto/dh/dh_lib.c:114:9: Taking false branch
112.       ret->references = 1;
113.       ret->lock = CRYPTO_THREAD_lock_new();
114.       if (ret->lock == NULL) {
               ^
115.           OPENSSL_free(ret);
116.           return NULL;

crypto/dh/dh_lib.c:119:5: 
117.       }
118.   
119. >     ret->meth = DH_get_default_method();
120.   #ifndef OPENSSL_NO_ENGINE
121.       ret->flags = ret->meth->flags;  /* early default init */

crypto/dh/dh_lib.c:71:1: start of procedure DH_get_default_method()
  69.   }
  70.   
  71. > const DH_METHOD *DH_get_default_method(void)
  72.   {
  73.       if (!default_DH_method)

crypto/dh/dh_lib.c:73:10: Taking false branch
  71.   const DH_METHOD *DH_get_default_method(void)
  72.   {
  73.       if (!default_DH_method)
                 ^
  74.           default_DH_method = DH_OpenSSL();
  75.       return default_DH_method;

crypto/dh/dh_lib.c:75:5: 
  73.       if (!default_DH_method)
  74.           default_DH_method = DH_OpenSSL();
  75. >     return default_DH_method;
  76.   }
  77.   

crypto/dh/dh_lib.c:76:1: return from a call to DH_get_default_method
  74.           default_DH_method = DH_OpenSSL();
  75.       return default_DH_method;
  76. > }
  77.   
  78.   int DH_set_method(DH *dh, const DH_METHOD *meth)

crypto/dh/dh_lib.c:121:5: 
119.       ret->meth = DH_get_default_method();
120.   #ifndef OPENSSL_NO_ENGINE
121. >     ret->flags = ret->meth->flags;  /* early default init */
122.       if (engine) {
123.           if (!ENGINE_init(engine)) {

crypto/dh/dh_lib.c:122:9: Taking false branch
120.   #ifndef OPENSSL_NO_ENGINE
121.       ret->flags = ret->meth->flags;  /* early default init */
122.       if (engine) {
               ^
123.           if (!ENGINE_init(engine)) {
124.               DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);

crypto/dh/dh_lib.c:129:9: 
127.           ret->engine = engine;
128.       } else
129. >         ret->engine = ENGINE_get_default_DH();
130.       if (ret->engine) {
131.           ret->meth = ENGINE_get_DH(ret->engine);

crypto/engine/tb_dh.c:101:1: start of procedure ENGINE_get_default_DH()
  99.    * references).
  100.    */
  101. > ENGINE *ENGINE_get_default_DH(void)
  102.   {
  103.       return engine_table_select(&dh_table, dummy_nid);

crypto/engine/tb_dh.c:103:5: 
  101.   ENGINE *ENGINE_get_default_DH(void)
  102.   {
  103. >     return engine_table_select(&dh_table, dummy_nid);
  104.   }
  105.   

crypto/engine/eng_table.c:233:1: start of procedure engine_table_select()
    231.   /* return a functional reference for a given 'nid' */
    232.   #ifndef ENGINE_TABLE_DEBUG
    233. > ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)
    234.   #else
    235.   ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,

crypto/engine/eng_table.c:239:5: 
    237.   #endif
    238.   {
    239. >     ENGINE *ret = NULL;
    240.       ENGINE_PILE tmplate, *fnd = NULL;
    241.       int initres, loop = 0;

crypto/engine/eng_table.c:240:5: 
    238.   {
    239.       ENGINE *ret = NULL;
    240. >     ENGINE_PILE tmplate, *fnd = NULL;
    241.       int initres, loop = 0;
    242.   

crypto/engine/eng_table.c:241:5: 
    239.       ENGINE *ret = NULL;
    240.       ENGINE_PILE tmplate, *fnd = NULL;
    241. >     int initres, loop = 0;
    242.   
    243.       if (!(*table)) {

crypto/engine/eng_table.c:243:11: 
    241.       int initres, loop = 0;
    242.   
    243. >     if (!(*table)) {
    244.   #ifdef ENGINE_TABLE_DEBUG
    245.           fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, nothing "

crypto/engine/eng_table.c:243:10: Taking true branch
    241.       int initres, loop = 0;
    242.   
    243.       if (!(*table)) {
                    ^
    244.   #ifdef ENGINE_TABLE_DEBUG
    245.           fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, nothing "

crypto/engine/eng_table.c:248:9: 
    246.                   "registered!\n", f, l, nid);
    247.   #endif
    248. >         return NULL;
    249.       }
    250.       ERR_set_mark();

crypto/engine/eng_table.c:329:1: return from a call to engine_table_select
    327.       ERR_pop_to_mark();
    328.       return ret;
    329. > }
    330.   
    331.   /* Table enumeration */

crypto/engine/tb_dh.c:104:1: return from a call to ENGINE_get_default_DH
  102.   {
  103.       return engine_table_select(&dh_table, dummy_nid);
  104. > }
  105.   
  106.   /* Obtains an DH implementation from an ENGINE functional reference */

crypto/dh/dh_lib.c:130:9: Taking false branch
128.       } else
129.           ret->engine = ENGINE_get_default_DH();
130.       if (ret->engine) {
               ^
131.           ret->meth = ENGINE_get_DH(ret->engine);
132.           if (ret->meth == NULL) {

crypto/dh/dh_lib.c:139:5: 
137.   #endif
138.   
139. >     ret->flags = ret->meth->flags;
140.   
141.       if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data))

crypto/dh/dh_lib.c:141:10: 
139.       ret->flags = ret->meth->flags;
140.   
141. >     if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data))
142.           goto err;
143.   

crypto/ex_data.c:304:1: start of procedure CRYPTO_new_ex_data()
  302.    * to the global "ex_data" state (ie. class definitions), not 'ad' itself.
  303.    */
  304. > int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)
  305.   {
  306.       int mx, i;

crypto/ex_data.c:308:5: 
  306.       int mx, i;
  307.       void *ptr;
  308. >     EX_CALLBACK **storage = NULL;
  309.       EX_CALLBACK *stack[10];
  310.       EX_CALLBACKS *ip = get_and_lock(class_index);

crypto/ex_data.c:310:5: 
  308.       EX_CALLBACK **storage = NULL;
  309.       EX_CALLBACK *stack[10];
  310. >     EX_CALLBACKS *ip = get_and_lock(class_index);
  311.   
  312.       if (ip == NULL)

crypto/ex_data.c:149:1: start of procedure get_and_lock()
    147.    * a given class.  On success, *holds the lock.*
    148.    */
    149. > static EX_CALLBACKS *get_and_lock(int class_index)
    150.   {
    151.       EX_CALLBACKS *ip;

crypto/ex_data.c:153:9: Taking false branch
    151.       EX_CALLBACKS *ip;
    152.   
    153.       if (class_index < 0 || class_index >= CRYPTO_EX_INDEX__COUNT) {
                   ^
    154.           CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_PASSED_INVALID_ARGUMENT);
    155.           return NULL;

crypto/ex_data.c:153:28: Taking false branch
    151.       EX_CALLBACKS *ip;
    152.   
    153.       if (class_index < 0 || class_index >= CRYPTO_EX_INDEX__COUNT) {
                                      ^
    154.           CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_PASSED_INVALID_ARGUMENT);
    155.           return NULL;

crypto/ex_data.c:158:5: 
    156.       }
    157.   
    158. >     CRYPTO_THREAD_run_once(&ex_data_init, do_ex_data_init);
    159.   
    160.       if (ex_data_lock == NULL) {

crypto/threads_pthread.c:104:1: start of procedure CRYPTO_THREAD_run_once()
      102.   }
      103.   
      104. > int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
      105.   {
      106.       if (pthread_once(once, init) != 0)

crypto/threads_pthread.c:106:9: Taking true branch
      104.   int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
      105.   {
      106.       if (pthread_once(once, init) != 0)
                     ^
      107.           return 0;
      108.   

crypto/threads_pthread.c:107:9: 
      105.   {
      106.       if (pthread_once(once, init) != 0)
      107. >         return 0;
      108.   
      109.       return 1;

crypto/threads_pthread.c:110:1: return from a call to CRYPTO_THREAD_run_once
      108.   
      109.       return 1;
      110. > }
      111.   
      112.   int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *))

crypto/ex_data.c:160:9: Taking true branch
    158.       CRYPTO_THREAD_run_once(&ex_data_init, do_ex_data_init);
    159.   
    160.       if (ex_data_lock == NULL) {
                   ^
    161.           /*
    162.            * This can happen in normal operation when using CRYPTO_mem_leaks().

crypto/ex_data.c:170:10: 
    168.            * ignore this operation. We just treat it as an error.
    169.            */
    170. >          return NULL;
    171.       }
    172.   

crypto/ex_data.c:176:1: return from a call to get_and_lock
    174.       CRYPTO_THREAD_write_lock(ex_data_lock);
    175.       return ip;
    176. > }
    177.   
    178.   static void cleanup_cb(EX_CALLBACK *funcs)

crypto/ex_data.c:312:9: Taking true branch
  310.       EX_CALLBACKS *ip = get_and_lock(class_index);
  311.   
  312.       if (ip == NULL)
                 ^
  313.           return 0;
  314.   

crypto/ex_data.c:313:9: 
  311.   
  312.       if (ip == NULL)
  313. >         return 0;
  314.   
  315.       ad->sk = NULL;

crypto/ex_data.c:343:1: return from a call to CRYPTO_new_ex_data
  341.           OPENSSL_free(storage);
  342.       return 1;
  343. > }
  344.   
  345.   /*

crypto/dh/dh_lib.c:141:10: Taking true branch
139.       ret->flags = ret->meth->flags;
140.   
141.       if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data))
                ^
142.           goto err;
143.   

crypto/dh/dh_lib.c:146:1: 
144.       if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
145.           DHerr(DH_F_DH_NEW_METHOD, ERR_R_INIT_FAIL);
146. > err:
147.           DH_free(ret);
148.           ret = NULL;

crypto/dh/dh_lib.c:147:9: Skipping DH_free(): empty list of specs
145.           DHerr(DH_F_DH_NEW_METHOD, ERR_R_INIT_FAIL);
146.   err:
147.           DH_free(ret);
               ^
148.           ret = NULL;
149.       }

DH *DH_new_method(ENGINE *engine)
{
    DH *ret = OPENSSL_zalloc(sizeof(*ret));
    if (ret == NULL) {
        DHerr(DH_F_DH_NEW_METHOD, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    ret->references = 1;
    ret->lock = CRYPTO_THREAD_lock_new();
    if (ret->lock == NULL) {
        OPENSSL_free(ret);
        return NULL;
    }
    ret->meth = DH_get_default_method();
#ifndef OPENSSL_NO_ENGINE
    ret->flags = ret->meth->flags;
    if (engine) {
        if (!ENGINE_init(engine)) {
            DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);
            goto err;
        }
        ret->engine = engine;
    } else
        ret->engine = ENGINE_get_default_DH();
    if (ret->engine) {
        ret->meth = ENGINE_get_DH(ret->engine);
        if (ret->meth == NULL) {
            DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);
            goto err;
        }
    }
#endif
    ret->flags = ret->meth->flags;
    if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data))
        goto err;
    if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
        DHerr(DH_F_DH_NEW_METHOD, ERR_R_INIT_FAIL);
err:
        DH_free(ret);
        ret = NULL;
    }
    return ret;
}
['DH *DH_new_method(ENGINE *engine)\n{\n    DH *ret = OPENSSL_zalloc(sizeof(*ret));\n    if (ret == NULL) {\n        DHerr(DH_F_DH_NEW_METHOD, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    ret->references = 1;\n    ret->lock = CRYPTO_THREAD_lock_new();\n    if (ret->lock == NULL) {\n        OPENSSL_free(ret);\n        return NULL;\n    }\n    ret->meth = DH_get_default_method();\n#ifndef OPENSSL_NO_ENGINE\n    ret->flags = ret->meth->flags;\n    if (engine) {\n        if (!ENGINE_init(engine)) {\n            DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);\n            goto err;\n        }\n        ret->engine = engine;\n    } else\n        ret->engine = ENGINE_get_default_DH();\n    if (ret->engine) {\n        ret->meth = ENGINE_get_DH(ret->engine);\n        if (ret->meth == NULL) {\n            DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);\n            goto err;\n        }\n    }\n#endif\n    ret->flags = ret->meth->flags;\n    if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data))\n        goto err;\n    if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {\n        DHerr(DH_F_DH_NEW_METHOD, ERR_R_INIT_FAIL);\nerr:\n        DH_free(ret);\n        ret = NULL;\n    }\n    return ret;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)\n{\n    CRYPTO_RWLOCK *lock = OPENSSL_zalloc(sizeof(pthread_rwlock_t));\n    if (lock == NULL)\n        return NULL;\n    if (pthread_rwlock_init(lock, NULL) != 0) {\n        OPENSSL_free(lock);\n        return NULL;\n    }\n    return lock;\n}', 'const DH_METHOD *DH_get_default_method(void)\n{\n    if (!default_DH_method)\n        default_DH_method = DH_OpenSSL();\n    return default_DH_method;\n}', 'ENGINE *ENGINE_get_default_DH(void)\n{\n    return engine_table_select(&dh_table, dummy_nid);\n}', 'ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)\n#else\nENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,\n                                int l)\n#endif\n{\n    ENGINE *ret = NULL;\n    ENGINE_PILE tmplate, *fnd = NULL;\n    int initres, loop = 0;\n    if (!(*table)) {\n#ifdef ENGINE_TABLE_DEBUG\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, nothing "\n                "registered!\\n", f, l, nid);\n#endif\n        return NULL;\n    }\n    ERR_set_mark();\n    CRYPTO_THREAD_write_lock(global_engine_lock);\n    if (!int_table_check(table, 0))\n        goto end;\n    tmplate.nid = nid;\n    fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);\n    if (!fnd)\n        goto end;\n    if (fnd->funct && engine_unlocked_init(fnd->funct)) {\n#ifdef ENGINE_TABLE_DEBUG\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "\n                "ENGINE \'%s\' cached\\n", f, l, nid, fnd->funct->id);\n#endif\n        ret = fnd->funct;\n        goto end;\n    }\n    if (fnd->uptodate) {\n        ret = fnd->funct;\n        goto end;\n    }\n trynext:\n    ret = sk_ENGINE_value(fnd->sk, loop++);\n    if (!ret) {\n#ifdef ENGINE_TABLE_DEBUG\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "\n                "registered implementations would initialise\\n", f, l, nid);\n#endif\n        goto end;\n    }\n    if ((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT))\n        initres = engine_unlocked_init(ret);\n    else\n        initres = 0;\n    if (initres) {\n        if ((fnd->funct != ret) && engine_unlocked_init(ret)) {\n            if (fnd->funct)\n                engine_unlocked_finish(fnd->funct, 0);\n            fnd->funct = ret;\n#ifdef ENGINE_TABLE_DEBUG\n            fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, "\n                    "setting default to \'%s\'\\n", f, l, nid, ret->id);\n#endif\n        }\n#ifdef ENGINE_TABLE_DEBUG\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "\n                "newly initialised \'%s\'\\n", f, l, nid, ret->id);\n#endif\n        goto end;\n    }\n    goto trynext;\n end:\n    if (fnd)\n        fnd->uptodate = 1;\n#ifdef ENGINE_TABLE_DEBUG\n    if (ret)\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "\n                "ENGINE \'%s\'\\n", f, l, nid, ret->id);\n    else\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "\n                "\'no matching ENGINE\'\\n", f, l, nid);\n#endif\n    CRYPTO_THREAD_unlock(global_engine_lock);\n    ERR_pop_to_mark();\n    return ret;\n}', 'int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)\n{\n    int mx, i;\n    void *ptr;\n    EX_CALLBACK **storage = NULL;\n    EX_CALLBACK *stack[10];\n    EX_CALLBACKS *ip = get_and_lock(class_index);\n    if (ip == NULL)\n        return 0;\n    ad->sk = NULL;\n    mx = sk_EX_CALLBACK_num(ip->meth);\n    if (mx > 0) {\n        if (mx < (int)OSSL_NELEM(stack))\n            storage = stack;\n        else\n            storage = OPENSSL_malloc(sizeof(*storage) * mx);\n        if (storage != NULL)\n            for (i = 0; i < mx; i++)\n                storage[i] = sk_EX_CALLBACK_value(ip->meth, i);\n    }\n    CRYPTO_THREAD_unlock(ex_data_lock);\n    if (mx > 0 && storage == NULL) {\n        CRYPTOerr(CRYPTO_F_CRYPTO_NEW_EX_DATA, ERR_R_MALLOC_FAILURE);\n        return 0;\n    }\n    for (i = 0; i < mx; i++) {\n        if (storage[i] && storage[i]->new_func) {\n            ptr = CRYPTO_get_ex_data(ad, i);\n            storage[i]->new_func(obj, ptr, ad, i,\n                                 storage[i]->argl, storage[i]->argp);\n        }\n    }\n    if (storage != stack)\n        OPENSSL_free(storage);\n    return 1;\n}', 'static EX_CALLBACKS *get_and_lock(int class_index)\n{\n    EX_CALLBACKS *ip;\n    if (class_index < 0 || class_index >= CRYPTO_EX_INDEX__COUNT) {\n        CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_PASSED_INVALID_ARGUMENT);\n        return NULL;\n    }\n    CRYPTO_THREAD_run_once(&ex_data_init, do_ex_data_init);\n    if (ex_data_lock == NULL) {\n         return NULL;\n    }\n    ip = &ex_data[class_index];\n    CRYPTO_THREAD_write_lock(ex_data_lock);\n    return ip;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n    if (pthread_once(once, init) != 0)\n        return 0;\n    return 1;\n}']