crypto/evp/pmeth_lib.c:182: error: MEMORY_LEAK
  memory dynamically allocated by call to `CRYPTO_zalloc()` at line 165, column 11 is not reachable after line 182, column 13.
Showing all 86 steps of the trace


crypto/evp/pmeth_lib.c:128:1: start of procedure int_ctx_new()
126.   }
127.   
128. > static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
129.   {
130.       EVP_PKEY_CTX *ret;

crypto/evp/pmeth_lib.c:132:9: Taking true branch
130.       EVP_PKEY_CTX *ret;
131.       const EVP_PKEY_METHOD *pmeth;
132.       if (id == -1) {
               ^
133.           if (!pkey || !pkey->ameth)
134.               return NULL;

crypto/evp/pmeth_lib.c:133:14: Taking false branch
131.       const EVP_PKEY_METHOD *pmeth;
132.       if (id == -1) {
133.           if (!pkey || !pkey->ameth)
                    ^
134.               return NULL;
135.           id = pkey->ameth->pkey_id;

crypto/evp/pmeth_lib.c:133:23: Taking false branch
131.       const EVP_PKEY_METHOD *pmeth;
132.       if (id == -1) {
133.           if (!pkey || !pkey->ameth)
                             ^
134.               return NULL;
135.           id = pkey->ameth->pkey_id;

crypto/evp/pmeth_lib.c:135:9: 
133.           if (!pkey || !pkey->ameth)
134.               return NULL;
135. >         id = pkey->ameth->pkey_id;
136.       }
137.   #ifndef OPENSSL_NO_ENGINE

crypto/evp/pmeth_lib.c:138:9: Taking true branch
136.       }
137.   #ifndef OPENSSL_NO_ENGINE
138.       if (pkey && pkey->engine)
               ^
139.           e = pkey->engine;
140.       /* Try to find an ENGINE which implements this method */

crypto/evp/pmeth_lib.c:138:17: Taking false branch
136.       }
137.   #ifndef OPENSSL_NO_ENGINE
138.       if (pkey && pkey->engine)
                       ^
139.           e = pkey->engine;
140.       /* Try to find an ENGINE which implements this method */

crypto/evp/pmeth_lib.c:141:9: Taking false branch
139.           e = pkey->engine;
140.       /* Try to find an ENGINE which implements this method */
141.       if (e) {
               ^
142.           if (!ENGINE_init(e)) {
143.               EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB);

crypto/evp/pmeth_lib.c:147:9: 
145.           }
146.       } else
147. >         e = ENGINE_get_pkey_meth_engine(id);
148.   
149.       /*

crypto/engine/tb_pkmeth.c:109:1: start of procedure ENGINE_get_pkey_meth_engine()
  107.    * references) for a given pkey_meth 'nid'
  108.    */
  109. > ENGINE *ENGINE_get_pkey_meth_engine(int nid)
  110.   {
  111.       return engine_table_select(&pkey_meth_table, nid);

crypto/engine/tb_pkmeth.c:111:5: 
  109.   ENGINE *ENGINE_get_pkey_meth_engine(int nid)
  110.   {
  111. >     return engine_table_select(&pkey_meth_table, nid);
  112.   }
  113.   

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_pkmeth.c:112:1: return from a call to ENGINE_get_pkey_meth_engine
  110.   {
  111.       return engine_table_select(&pkey_meth_table, nid);
  112. > }
  113.   
  114.   /* Obtains a pkey_meth implementation from an ENGINE functional reference */

crypto/evp/pmeth_lib.c:154:9: Taking false branch
152.        */
153.   
154.       if (e)
               ^
155.           pmeth = ENGINE_get_pkey_meth(e, id);
156.       else

crypto/evp/pmeth_lib.c:158:9: 
156.       else
157.   #endif
158. >         pmeth = EVP_PKEY_meth_find(id);
159.   
160.       if (pmeth == NULL) {

crypto/evp/pmeth_lib.c:109:1: start of procedure EVP_PKEY_meth_find()
  107.                                pmeth);
  108.   
  109. > const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)
  110.   {
  111.       EVP_PKEY_METHOD tmp;

crypto/evp/pmeth_lib.c:112:5: 
  110.   {
  111.       EVP_PKEY_METHOD tmp;
  112. >     const EVP_PKEY_METHOD *t = &tmp, **ret;
  113.       tmp.pkey_id = type;
  114.       if (app_pkey_methods) {

crypto/evp/pmeth_lib.c:113:5: 
  111.       EVP_PKEY_METHOD tmp;
  112.       const EVP_PKEY_METHOD *t = &tmp, **ret;
  113. >     tmp.pkey_id = type;
  114.       if (app_pkey_methods) {
  115.           int idx;

crypto/evp/pmeth_lib.c:114:9: Taking true branch
  112.       const EVP_PKEY_METHOD *t = &tmp, **ret;
  113.       tmp.pkey_id = type;
  114.       if (app_pkey_methods) {
                 ^
  115.           int idx;
  116.           idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp);

crypto/evp/pmeth_lib.c:116:9: 
  114.       if (app_pkey_methods) {
  115.           int idx;
  116. >         idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp);
  117.           if (idx >= 0)
  118.               return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);

crypto/include/internal/evp_int.h:122:1: start of procedure sk_EVP_PKEY_METHOD_find()
    120.   } /* EVP_PKEY_METHOD */ ;
    121.   
    122. > DEFINE_STACK_OF_CONST(EVP_PKEY_METHOD)
    123.   
    124.   void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx);

crypto/stack/stack.c:248:1: start of procedure sk_find()
      246.   }
      247.   
      248. > int sk_find(_STACK *st, void *data)
      249.   {
      250.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);

crypto/stack/stack.c:250:5: 
      248.   int sk_find(_STACK *st, void *data)
      249.   {
      250. >     return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      251.   }
      252.   

crypto/stack/stack.c:224:1: start of procedure internal_find()
        222.   }
        223.   
        224. > static int internal_find(_STACK *st, void *data, int ret_val_options)
        225.   {
        226.       const void *const *r;

crypto/stack/stack.c:229:9: Taking false branch
        227.       int i;
        228.   
        229.       if (st == NULL)
                       ^
        230.           return -1;
        231.   

crypto/stack/stack.c:232:9: Taking true branch
        230.           return -1;
        231.   
        232.       if (st->comp == NULL) {
                       ^
        233.           for (i = 0; i < st->num; i++)
        234.               if (st->data[i] == data)

crypto/stack/stack.c:233:14: 
        231.   
        232.       if (st->comp == NULL) {
        233. >         for (i = 0; i < st->num; i++)
        234.               if (st->data[i] == data)
        235.                   return (i);

crypto/stack/stack.c:233:21: Loop condition is true. Entering loop body
        231.   
        232.       if (st->comp == NULL) {
        233.           for (i = 0; i < st->num; i++)
                                   ^
        234.               if (st->data[i] == data)
        235.                   return (i);

crypto/stack/stack.c:234:17: Taking true branch
        232.       if (st->comp == NULL) {
        233.           for (i = 0; i < st->num; i++)
        234.               if (st->data[i] == data)
                               ^
        235.                   return (i);
        236.           return (-1);

crypto/stack/stack.c:235:17: 
        233.           for (i = 0; i < st->num; i++)
        234.               if (st->data[i] == data)
        235. >                 return (i);
        236.           return (-1);
        237.       }

crypto/stack/stack.c:246:1: return from a call to internal_find
        244.           return (-1);
        245.       return (int)((char **)r - st->data);
        246. > }
        247.   
        248.   int sk_find(_STACK *st, void *data)

crypto/stack/stack.c:251:1: return from a call to sk_find
      249.   {
      250.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      251. > }
      252.   
      253.   int sk_find_ex(_STACK *st, void *data)

crypto/include/internal/evp_int.h:122:1: return from a call to sk_EVP_PKEY_METHOD_find
    120.   } /* EVP_PKEY_METHOD */ ;
    121.   
    122. > DEFINE_STACK_OF_CONST(EVP_PKEY_METHOD)
    123.   
    124.   void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx);

crypto/evp/pmeth_lib.c:117:13: Taking true branch
  115.           int idx;
  116.           idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp);
  117.           if (idx >= 0)
                     ^
  118.               return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
  119.       }

crypto/evp/pmeth_lib.c:118:13: 
  116.           idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp);
  117.           if (idx >= 0)
  118. >             return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);
  119.       }
  120.       ret = OBJ_bsearch_pmeth(&t, standard_methods,

crypto/include/internal/evp_int.h:122:1: start of procedure sk_EVP_PKEY_METHOD_value()
    120.   } /* EVP_PKEY_METHOD */ ;
    121.   
    122. > DEFINE_STACK_OF_CONST(EVP_PKEY_METHOD)
    123.   
    124.   void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx);

crypto/stack/stack.c:323:1: start of procedure sk_value()
      321.   }
      322.   
      323. > void *sk_value(const _STACK *st, int i)
      324.   {
      325.       if (!st || (i < 0) || (i >= st->num))

crypto/stack/stack.c:325:10: Taking false branch
      323.   void *sk_value(const _STACK *st, int i)
      324.   {
      325.       if (!st || (i < 0) || (i >= st->num))
                      ^
      326.           return NULL;
      327.       return st->data[i];

crypto/stack/stack.c:325:17: Taking false branch
      323.   void *sk_value(const _STACK *st, int i)
      324.   {
      325.       if (!st || (i < 0) || (i >= st->num))
                             ^
      326.           return NULL;
      327.       return st->data[i];

crypto/stack/stack.c:325:28: Taking false branch
      323.   void *sk_value(const _STACK *st, int i)
      324.   {
      325.       if (!st || (i < 0) || (i >= st->num))
                                        ^
      326.           return NULL;
      327.       return st->data[i];

crypto/stack/stack.c:327:5: 
      325.       if (!st || (i < 0) || (i >= st->num))
      326.           return NULL;
      327. >     return st->data[i];
      328.   }
      329.   

crypto/stack/stack.c:328:1: return from a call to sk_value
      326.           return NULL;
      327.       return st->data[i];
      328. > }
      329.   
      330.   void *sk_set(_STACK *st, int i, void *value)

crypto/include/internal/evp_int.h:122:1: return from a call to sk_EVP_PKEY_METHOD_value
    120.   } /* EVP_PKEY_METHOD */ ;
    121.   
    122. > DEFINE_STACK_OF_CONST(EVP_PKEY_METHOD)
    123.   
    124.   void evp_pkey_set_cb_translate(BN_GENCB *cb, EVP_PKEY_CTX *ctx);

crypto/evp/pmeth_lib.c:126:1: return from a call to EVP_PKEY_meth_find
  124.           return NULL;
  125.       return *ret;
  126. > }
  127.   
  128.   static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)

crypto/evp/pmeth_lib.c:160:9: Taking false branch
158.           pmeth = EVP_PKEY_meth_find(id);
159.   
160.       if (pmeth == NULL) {
               ^
161.           EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM);
162.           return NULL;

crypto/evp/pmeth_lib.c:165:5: 
163.       }
164.   
165. >     ret = OPENSSL_zalloc(sizeof(*ret));
166.       if (ret == NULL) {
167.   #ifndef OPENSSL_NO_ENGINE

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/evp/pmeth_lib.c:166:9: Taking false branch
164.   
165.       ret = OPENSSL_zalloc(sizeof(*ret));
166.       if (ret == NULL) {
               ^
167.   #ifndef OPENSSL_NO_ENGINE
168.           ENGINE_finish(e);

crypto/evp/pmeth_lib.c:173:5: 
171.           return NULL;
172.       }
173. >     ret->engine = e;
174.       ret->pmeth = pmeth;
175.       ret->operation = EVP_PKEY_OP_UNDEFINED;

crypto/evp/pmeth_lib.c:174:5: 
172.       }
173.       ret->engine = e;
174. >     ret->pmeth = pmeth;
175.       ret->operation = EVP_PKEY_OP_UNDEFINED;
176.       ret->pkey = pkey;

crypto/evp/pmeth_lib.c:175:5: 
173.       ret->engine = e;
174.       ret->pmeth = pmeth;
175. >     ret->operation = EVP_PKEY_OP_UNDEFINED;
176.       ret->pkey = pkey;
177.       if (pkey)

crypto/evp/pmeth_lib.c:176:5: 
174.       ret->pmeth = pmeth;
175.       ret->operation = EVP_PKEY_OP_UNDEFINED;
176. >     ret->pkey = pkey;
177.       if (pkey)
178.           EVP_PKEY_up_ref(pkey);

crypto/evp/pmeth_lib.c:177:9: Taking true branch
175.       ret->operation = EVP_PKEY_OP_UNDEFINED;
176.       ret->pkey = pkey;
177.       if (pkey)
               ^
178.           EVP_PKEY_up_ref(pkey);
179.   

crypto/evp/pmeth_lib.c:178:9: 
176.       ret->pkey = pkey;
177.       if (pkey)
178. >         EVP_PKEY_up_ref(pkey);
179.   
180.       if (pmeth->init) {

crypto/evp/p_lib.c:208:1: start of procedure EVP_PKEY_up_ref()
  206.   }
  207.   
  208. > void EVP_PKEY_up_ref(EVP_PKEY *pkey)
  209.   {
  210.       int i;

crypto/evp/p_lib.c:211:5: 
  209.   {
  210.       int i;
  211. >     CRYPTO_atomic_add(&pkey->references, 1, &i, pkey->lock);
  212.   }
  213.   

crypto/threads_pthread.c:151:1: start of procedure CRYPTO_atomic_add()
    149.   }
    150.   
    151. > int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
    152.   {
    153.   #ifdef __ATOMIC_RELAXED

crypto/threads_pthread.c:154:5: 
    152.   {
    153.   #ifdef __ATOMIC_RELAXED
    154. >     *ret = __atomic_add_fetch(val, amount, __ATOMIC_RELAXED);
    155.   #else
    156.       if (!CRYPTO_THREAD_write_lock(lock))

crypto/threads_pthread.c:166:5: 
    164.   #endif
    165.   
    166. >     return 1;
    167.   }
    168.   

crypto/threads_pthread.c:167:1: return from a call to CRYPTO_atomic_add
    165.   
    166.       return 1;
    167. > }
    168.   
    169.   #endif

crypto/evp/p_lib.c:212:1: return from a call to EVP_PKEY_up_ref
  210.       int i;
  211.       CRYPTO_atomic_add(&pkey->references, 1, &i, pkey->lock);
  212. > }
  213.   
  214.   /*

crypto/evp/pmeth_lib.c:180:9: Taking true branch
178.           EVP_PKEY_up_ref(pkey);
179.   
180.       if (pmeth->init) {
               ^
181.           if (pmeth->init(ret) <= 0) {
182.               EVP_PKEY_CTX_free(ret);

crypto/evp/pmeth_lib.c:181:13: Taking true branch
179.   
180.       if (pmeth->init) {
181.           if (pmeth->init(ret) <= 0) {
                   ^
182.               EVP_PKEY_CTX_free(ret);
183.               return NULL;

crypto/evp/pmeth_lib.c:182:13: Skipping EVP_PKEY_CTX_free(): empty list of specs
180.       if (pmeth->init) {
181.           if (pmeth->init(ret) <= 0) {
182.               EVP_PKEY_CTX_free(ret);
                   ^
183.               return NULL;
184.           }

static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
{
    EVP_PKEY_CTX *ret;
    const EVP_PKEY_METHOD *pmeth;
    if (id == -1) {
        if (!pkey || !pkey->ameth)
            return NULL;
        id = pkey->ameth->pkey_id;
    }
#ifndef OPENSSL_NO_ENGINE
    if (pkey && pkey->engine)
        e = pkey->engine;
    if (e) {
        if (!ENGINE_init(e)) {
            EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB);
            return NULL;
        }
    } else
        e = ENGINE_get_pkey_meth_engine(id);
    if (e)
        pmeth = ENGINE_get_pkey_meth(e, id);
    else
#endif
        pmeth = EVP_PKEY_meth_find(id);
    if (pmeth == NULL) {
        EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM);
        return NULL;
    }
    ret = OPENSSL_zalloc(sizeof(*ret));
    if (ret == NULL) {
#ifndef OPENSSL_NO_ENGINE
        ENGINE_finish(e);
#endif
        EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    ret->engine = e;
    ret->pmeth = pmeth;
    ret->operation = EVP_PKEY_OP_UNDEFINED;
    ret->pkey = pkey;
    if (pkey)
        EVP_PKEY_up_ref(pkey);
    if (pmeth->init) {
        if (pmeth->init(ret) <= 0) {
            EVP_PKEY_CTX_free(ret);
            return NULL;
        }
    }
    return ret;
}
['static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)\n{\n    EVP_PKEY_CTX *ret;\n    const EVP_PKEY_METHOD *pmeth;\n    if (id == -1) {\n        if (!pkey || !pkey->ameth)\n            return NULL;\n        id = pkey->ameth->pkey_id;\n    }\n#ifndef OPENSSL_NO_ENGINE\n    if (pkey && pkey->engine)\n        e = pkey->engine;\n    if (e) {\n        if (!ENGINE_init(e)) {\n            EVPerr(EVP_F_INT_CTX_NEW, ERR_R_ENGINE_LIB);\n            return NULL;\n        }\n    } else\n        e = ENGINE_get_pkey_meth_engine(id);\n    if (e)\n        pmeth = ENGINE_get_pkey_meth(e, id);\n    else\n#endif\n        pmeth = EVP_PKEY_meth_find(id);\n    if (pmeth == NULL) {\n        EVPerr(EVP_F_INT_CTX_NEW, EVP_R_UNSUPPORTED_ALGORITHM);\n        return NULL;\n    }\n    ret = OPENSSL_zalloc(sizeof(*ret));\n    if (ret == NULL) {\n#ifndef OPENSSL_NO_ENGINE\n        ENGINE_finish(e);\n#endif\n        EVPerr(EVP_F_INT_CTX_NEW, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    ret->engine = e;\n    ret->pmeth = pmeth;\n    ret->operation = EVP_PKEY_OP_UNDEFINED;\n    ret->pkey = pkey;\n    if (pkey)\n        EVP_PKEY_up_ref(pkey);\n    if (pmeth->init) {\n        if (pmeth->init(ret) <= 0) {\n            EVP_PKEY_CTX_free(ret);\n            return NULL;\n        }\n    }\n    return ret;\n}', 'ENGINE *ENGINE_get_pkey_meth_engine(int nid)\n{\n    return engine_table_select(&pkey_meth_table, 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}', 'const EVP_PKEY_METHOD *EVP_PKEY_meth_find(int type)\n{\n    EVP_PKEY_METHOD tmp;\n    const EVP_PKEY_METHOD *t = &tmp, **ret;\n    tmp.pkey_id = type;\n    if (app_pkey_methods) {\n        int idx;\n        idx = sk_EVP_PKEY_METHOD_find(app_pkey_methods, &tmp);\n        if (idx >= 0)\n            return sk_EVP_PKEY_METHOD_value(app_pkey_methods, idx);\n    }\n    ret = OBJ_bsearch_pmeth(&t, standard_methods,\n                            sizeof(standard_methods) /\n                            sizeof(EVP_PKEY_METHOD *));\n    if (!ret || !*ret)\n        return NULL;\n    return *ret;\n}', 'int sk_find(_STACK *st, void *data)\n{\n    return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);\n}', 'static int internal_find(_STACK *st, void *data, int ret_val_options)\n{\n    const void *const *r;\n    int i;\n    if (st == NULL)\n        return -1;\n    if (st->comp == NULL) {\n        for (i = 0; i < st->num; i++)\n            if (st->data[i] == data)\n                return (i);\n        return (-1);\n    }\n    sk_sort(st);\n    if (data == NULL)\n        return (-1);\n    r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp,\n                        ret_val_options);\n    if (r == NULL)\n        return (-1);\n    return (int)((char **)r - st->data);\n}', 'void *sk_value(const _STACK *st, int i)\n{\n    if (!st || (i < 0) || (i >= st->num))\n        return NULL;\n    return st->data[i];\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}', 'void EVP_PKEY_up_ref(EVP_PKEY *pkey)\n{\n    int i;\n    CRYPTO_atomic_add(&pkey->references, 1, &i, pkey->lock);\n}', 'int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)\n{\n#ifdef __ATOMIC_RELAXED\n    *ret = __atomic_add_fetch(val, amount, __ATOMIC_RELAXED);\n#else\n    if (!CRYPTO_THREAD_write_lock(lock))\n        return 0;\n    *val += amount;\n    *ret  = *val;\n    if (!CRYPTO_THREAD_unlock(lock))\n        return 0;\n#endif\n    return 1;\n}']