crypto/engine/eng_cnf.c:183: error: USE_AFTER_FREE
  call to `ENGINE_finish()` eventually accesses memory that was invalidated by call to `free()` on line 183 indirectly during the call to `ENGINE_finish()`.
Showing all 22 steps of the trace


crypto/engine/eng_cnf.c:182:31: invalidation part of the trace starts here
180.       ENGINE *e;
181.   
182.       while ((e = sk_ENGINE_pop(initialized_engines)))
                                     ^
183.           ENGINE_finish(e);
184.       sk_ENGINE_free(initialized_engines);

crypto/engine/eng_cnf.c:182:31: global variable `initialized_engines` accessed here
  180.       ENGINE *e;
  181.   
  182.       while ((e = sk_ENGINE_pop(initialized_engines)))
                                       ^
  183.           ENGINE_finish(e);
  184.       sk_ENGINE_free(initialized_engines);

crypto/engine/eng_cnf.c:182:17: passed as argument to `sk_ENGINE_pop`
  180.       ENGINE *e;
  181.   
  182.       while ((e = sk_ENGINE_pop(initialized_engines)))
                         ^
  183.           ENGINE_finish(e);
  184.       sk_ENGINE_free(initialized_engines);

crypto/engine/eng_cnf.c:182:17: return from call to `sk_ENGINE_pop`
  180.       ENGINE *e;
  181.   
  182.       while ((e = sk_ENGINE_pop(initialized_engines)))
                         ^
  183.           ENGINE_finish(e);
  184.       sk_ENGINE_free(initialized_engines);

crypto/engine/eng_cnf.c:182:13: assigned
  180.       ENGINE *e;
  181.   
  182.       while ((e = sk_ENGINE_pop(initialized_engines)))
                     ^
  183.           ENGINE_finish(e);
  184.       sk_ENGINE_free(initialized_engines);

crypto/engine/eng_cnf.c:183:9: when calling `ENGINE_finish` here
  181.   
  182.       while ((e = sk_ENGINE_pop(initialized_engines)))
  183.           ENGINE_finish(e);
                 ^
  184.       sk_ENGINE_free(initialized_engines);
  185.       initialized_engines = NULL;

crypto/engine/eng_init.c:95:1: parameter `e` of ENGINE_finish
    93.   
    94.   /* The API (locked) version of "finish" */
    95. > int ENGINE_finish(ENGINE *e)
    96.   {
    97.       int to_return = 1;

crypto/engine/eng_init.c:102:17: when calling `engine_unlocked_finish` here
    100.           return 1;
    101.       CRYPTO_THREAD_write_lock(global_engine_lock);
    102.       to_return = engine_unlocked_finish(e, 1);
                           ^
    103.       CRYPTO_THREAD_unlock(global_engine_lock);
    104.       if (!to_return) {

crypto/engine/eng_init.c:44:1: parameter `e` of engine_unlocked_finish
      42.    * internally.
      43.    */
      44. > int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers)
      45.   {
      46.       int to_return = 1;

crypto/engine/eng_init.c:69:10: when calling `engine_free_util` here
      67.       REF_ASSERT_ISNT(e->funct_ref < 0);
      68.       /* Release the structural reference too */
      69.       if (!engine_free_util(e, 0)) {
                     ^
      70.           ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH, ENGINE_R_FINISH_FAILED);
      71.           return 0;

crypto/engine/eng_lib.c:71:1: parameter `e` of engine_free_util
        69.   }
        70.   
        71. > int engine_free_util(ENGINE *e, int not_locked)
        72.   {
        73.       int i;

crypto/engine/eng_lib.c:99:5: when calling `CRYPTO_free` here
        97.           e->destroy(e);
        98.       CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data);
        99.       OPENSSL_free(e);
                   ^
        100.       return 1;
        101.   }

crypto/mem.c:286:1: parameter `str` of CRYPTO_free
          284.   }
          285.   
          286. > void CRYPTO_free(void *str, const char *file, int line)
          287.   {
          288.       INCREMENT(free_count);

crypto/mem.c:303:5: was invalidated by call to `free()`
          301.       }
          302.   #else
          303.       free(str);
                     ^
          304.   #endif
          305.   }

crypto/engine/eng_cnf.c:182:31: use-after-lifetime part of the trace starts here
180.       ENGINE *e;
181.   
182.       while ((e = sk_ENGINE_pop(initialized_engines)))
                                     ^
183.           ENGINE_finish(e);
184.       sk_ENGINE_free(initialized_engines);

crypto/engine/eng_cnf.c:182:31: global variable `initialized_engines` accessed here
  180.       ENGINE *e;
  181.   
  182.       while ((e = sk_ENGINE_pop(initialized_engines)))
                                       ^
  183.           ENGINE_finish(e);
  184.       sk_ENGINE_free(initialized_engines);

crypto/engine/eng_cnf.c:182:17: passed as argument to `sk_ENGINE_pop`
  180.       ENGINE *e;
  181.   
  182.       while ((e = sk_ENGINE_pop(initialized_engines)))
                         ^
  183.           ENGINE_finish(e);
  184.       sk_ENGINE_free(initialized_engines);

crypto/engine/eng_cnf.c:182:17: return from call to `sk_ENGINE_pop`
  180.       ENGINE *e;
  181.   
  182.       while ((e = sk_ENGINE_pop(initialized_engines)))
                         ^
  183.           ENGINE_finish(e);
  184.       sk_ENGINE_free(initialized_engines);

crypto/engine/eng_cnf.c:182:13: assigned
  180.       ENGINE *e;
  181.   
  182.       while ((e = sk_ENGINE_pop(initialized_engines)))
                     ^
  183.           ENGINE_finish(e);
  184.       sk_ENGINE_free(initialized_engines);

crypto/engine/eng_cnf.c:183:9: when calling `ENGINE_finish` here
  181.   
  182.       while ((e = sk_ENGINE_pop(initialized_engines)))
  183.           ENGINE_finish(e);
                 ^
  184.       sk_ENGINE_free(initialized_engines);
  185.       initialized_engines = NULL;

crypto/mem.c:286:1: parameter `str` of CRYPTO_free
    284.   }
    285.   
    286. > void CRYPTO_free(void *str, const char *file, int line)
    287.   {
    288.       INCREMENT(free_count);

crypto/mem.c:303:5: invalid access occurs here
    301.       }
    302.   #else
    303.       free(str);
               ^
    304.   #endif
    305.   }

void CRYPTO_free(void *str, const char *file, int line)
{
    INCREMENT(free_count);
    if (free_impl != NULL && free_impl != &CRYPTO_free) {
        free_impl(str, file, line);
        return;
    }
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
    if (call_malloc_debug) {
        CRYPTO_mem_debug_free(str, 0, file, line);
        free(str);
        CRYPTO_mem_debug_free(str, 1, file, line);
    } else {
        free(str);
    }
#else
    free(str);
#endif
}
['static void int_engine_module_finish(CONF_IMODULE *md)\n{\n    ENGINE *e;\n    while ((e = sk_ENGINE_pop(initialized_engines)))\n        ENGINE_finish(e);\n    sk_ENGINE_free(initialized_engines);\n    initialized_engines = NULL;\n}', 'int ENGINE_finish(ENGINE *e)\n{\n    int to_return = 1;\n    if (e == NULL)\n        return 1;\n    CRYPTO_THREAD_write_lock(global_engine_lock);\n    to_return = engine_unlocked_finish(e, 1);\n    CRYPTO_THREAD_unlock(global_engine_lock);\n    if (!to_return) {\n        ENGINEerr(ENGINE_F_ENGINE_FINISH, ENGINE_R_FINISH_FAILED);\n        return 0;\n    }\n    return to_return;\n}', 'int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers)\n{\n    int to_return = 1;\n    e->funct_ref--;\n    engine_ref_debug(e, 1, -1);\n    if ((e->funct_ref == 0) && e->finish) {\n        if (unlock_for_handlers)\n            CRYPTO_THREAD_unlock(global_engine_lock);\n        to_return = e->finish(e);\n        if (unlock_for_handlers)\n            CRYPTO_THREAD_write_lock(global_engine_lock);\n        if (!to_return)\n            return 0;\n    }\n    REF_ASSERT_ISNT(e->funct_ref < 0);\n    if (!engine_free_util(e, 0)) {\n        ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH, ENGINE_R_FINISH_FAILED);\n        return 0;\n    }\n    return to_return;\n}', 'int engine_free_util(ENGINE *e, int not_locked)\n{\n    int i;\n    if (e == NULL)\n        return 1;\n#ifdef HAVE_ATOMICS\n    CRYPTO_DOWN_REF(&e->struct_ref, &i, global_engine_lock);\n#else\n    if (not_locked)\n        CRYPTO_atomic_add(&e->struct_ref, -1, &i, global_engine_lock);\n    else\n        i = --e->struct_ref;\n#endif\n    engine_ref_debug(e, 0, -1)\n    if (i > 0)\n        return 1;\n    REF_ASSERT_ISNT(i < 0);\n    engine_pkey_meths_free(e);\n    engine_pkey_asn1_meths_free(e);\n    if (e->destroy)\n        e->destroy(e);\n    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data);\n    OPENSSL_free(e);\n    return 1;\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n    INCREMENT(free_count);\n    if (free_impl != NULL && free_impl != &CRYPTO_free) {\n        free_impl(str, file, line);\n        return;\n    }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0, file, line);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1, file, line);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}']