crypto/rand/drbg_lib.c:685: error: MEMORY_LEAK
  memory dynamically allocated by call to `CRYPTO_secure_zalloc()` at line 644, column 12 is not reachable after line 685, column 5.
Showing all 67 steps of the trace


crypto/rand/drbg_lib.c:635:1: start of procedure drbg_setup()
633.    * Returns a pointer to the new DRBG instance on success, NULL on failure.
634.    */
635. > static RAND_DRBG *drbg_setup(const char *name, RAND_DRBG *parent)
636.   {
637.       RAND_DRBG *drbg;

crypto/rand/drbg_lib.c:639:9: Taking false branch
637.       RAND_DRBG *drbg;
638.   
639.       if (name == NULL) {
               ^
640.           RANDerr(RAND_F_DRBG_SETUP, ERR_R_INTERNAL_ERROR);
641.           return NULL;

crypto/rand/drbg_lib.c:644:5: 
642.       }
643.   
644. >     drbg = OPENSSL_secure_zalloc(sizeof(RAND_DRBG));
645.       if (drbg == NULL)
646.           return NULL;

crypto/mem_sec.c:129:1: start of procedure CRYPTO_secure_zalloc()
  127.   }
  128.   
  129. > void *CRYPTO_secure_zalloc(size_t num, const char *file, int line)
  130.   {
  131.       void *ret = CRYPTO_secure_malloc(num, file, line);

crypto/mem_sec.c:131:5: 
  129.   void *CRYPTO_secure_zalloc(size_t num, const char *file, int line)
  130.   {
  131. >     void *ret = CRYPTO_secure_malloc(num, file, line);
  132.   
  133.       if (ret != NULL)

crypto/mem_sec.c:109:1: start of procedure CRYPTO_secure_malloc()
    107.   }
    108.   
    109. > void *CRYPTO_secure_malloc(size_t num, const char *file, int line)
    110.   {
    111.   #ifdef IMPLEMENTED

crypto/mem_sec.c:115:10: Taking true branch
    113.       size_t actual_size;
    114.   
    115.       if (!secure_mem_initialized) {
                    ^
    116.           return CRYPTO_malloc(num, file, line);
    117.       }

crypto/mem_sec.c:116:9: 
    114.   
    115.       if (!secure_mem_initialized) {
    116. >         return CRYPTO_malloc(num, file, line);
    117.       }
    118.       CRYPTO_THREAD_write_lock(sec_malloc_lock);

crypto/mem.c:189:1: start of procedure CRYPTO_malloc()
      187.   #endif
      188.   
      189. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      190.   {
      191.       void *ret = NULL;

crypto/mem.c:191:5: 
      189.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      190.   {
      191. >     void *ret = NULL;
      192.   
      193.       INCREMENT(malloc_count);

crypto/mem.c:194:9: Taking false branch
      192.   
      193.       INCREMENT(malloc_count);
      194.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      195.           return malloc_impl(num, file, line);
      196.   

crypto/mem.c:197:9: Taking false branch
      195.           return malloc_impl(num, file, line);
      196.   
      197.       if (num == 0)
                     ^
      198.           return NULL;
      199.   

crypto/mem.c:201:5: 
      199.   
      200.       FAILTEST();
      201. >     allow_customize = 0;
      202.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
      203.       if (call_malloc_debug) {

crypto/mem.c:211:5: 
      209.       }
      210.   #else
      211. >     (void)(file); (void)(line);
      212.       ret = malloc(num);
      213.   #endif

crypto/mem.c:211:19: 
      209.       }
      210.   #else
      211. >     (void)(file); (void)(line);
      212.       ret = malloc(num);
      213.   #endif

crypto/mem.c:212:5: 
      210.   #else
      211.       (void)(file); (void)(line);
      212. >     ret = malloc(num);
      213.   #endif
      214.   

crypto/mem.c:215:5: 
      213.   #endif
      214.   
      215. >     return ret;
      216.   }
      217.   

crypto/mem.c:216:1: return from a call to CRYPTO_malloc
      214.   
      215.       return ret;
      216. > }
      217.   
      218.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem_sec.c:127:1: return from a call to CRYPTO_secure_malloc
    125.       return CRYPTO_malloc(num, file, line);
    126.   #endif /* IMPLEMENTED */
    127. > }
    128.   
    129.   void *CRYPTO_secure_zalloc(size_t num, const char *file, int line)

crypto/mem_sec.c:133:9: Taking true branch
  131.       void *ret = CRYPTO_secure_malloc(num, file, line);
  132.   
  133.       if (ret != NULL)
                 ^
  134.           memset(ret, 0, num);
  135.       return ret;

crypto/mem_sec.c:134:9: 
  132.   
  133.       if (ret != NULL)
  134. >         memset(ret, 0, num);
  135.       return ret;
  136.   }

crypto/mem_sec.c:135:5: 
  133.       if (ret != NULL)
  134.           memset(ret, 0, num);
  135. >     return ret;
  136.   }
  137.   

crypto/mem_sec.c:136:1: return from a call to CRYPTO_secure_zalloc
  134.           memset(ret, 0, num);
  135.       return ret;
  136. > }
  137.   
  138.   void CRYPTO_secure_free(void *ptr, const char *file, int line)

crypto/rand/drbg_lib.c:645:9: Taking false branch
643.   
644.       drbg = OPENSSL_secure_zalloc(sizeof(RAND_DRBG));
645.       if (drbg == NULL)
               ^
646.           return NULL;
647.   

crypto/rand/drbg_lib.c:648:5: 
646.           return NULL;
647.   
648. >     drbg->lock = CRYPTO_THREAD_glock_new(name);
649.       if (drbg->lock == NULL) {
650.           RANDerr(RAND_F_DRBG_SETUP, RAND_R_FAILED_TO_CREATE_LOCK);

crypto/init.c:727:1: start of procedure CRYPTO_THREAD_glock_new()
  725.    * Create a new global lock, return NULL on error.
  726.    */
  727. > CRYPTO_RWLOCK *CRYPTO_THREAD_glock_new(const char *name)
  728.   {
  729.       GLOBAL_LOCK *newlock;

crypto/init.c:731:9: Taking true branch
  729.       GLOBAL_LOCK *newlock;
  730.   
  731.       if (glock_lock == NULL && !RUN_ONCE(&glock_once, glock_init))
                 ^
  732.           return NULL;
  733.       if ((newlock = malloc(sizeof(*newlock))) == NULL)

crypto/init.c:731:32: 
  729.       GLOBAL_LOCK *newlock;
  730.   
  731. >     if (glock_lock == NULL && !RUN_ONCE(&glock_once, glock_init))
  732.           return NULL;
  733.       if ((newlock = malloc(sizeof(*newlock))) == NULL)

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

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

crypto/threads_pthread.c:110:5: 
    108.           return 0;
    109.   
    110. >     return 1;
    111.   }
    112.   

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

crypto/init.c:731:32: Condition is true
  729.       GLOBAL_LOCK *newlock;
  730.   
  731.       if (glock_lock == NULL && !RUN_ONCE(&glock_once, glock_init))
                                        ^
  732.           return NULL;
  733.       if ((newlock = malloc(sizeof(*newlock))) == NULL)

crypto/init.c:731:32: Taking false branch
  729.       GLOBAL_LOCK *newlock;
  730.   
  731.       if (glock_lock == NULL && !RUN_ONCE(&glock_once, glock_init))
                                        ^
  732.           return NULL;
  733.       if ((newlock = malloc(sizeof(*newlock))) == NULL)

crypto/init.c:733:9: Taking false branch
  731.       if (glock_lock == NULL && !RUN_ONCE(&glock_once, glock_init))
  732.           return NULL;
  733.       if ((newlock = malloc(sizeof(*newlock))) == NULL)
                 ^
  734.           return NULL;
  735.       if ((newlock->lock = CRYPTO_THREAD_lock_new()) == NULL) {

crypto/init.c:735:9: 
  733.       if ((newlock = malloc(sizeof(*newlock))) == NULL)
  734.           return NULL;
  735. >     if ((newlock->lock = CRYPTO_THREAD_lock_new()) == NULL) {
  736.           free(newlock);
  737.           return NULL;

crypto/threads_pthread.c:19:1: start of procedure CRYPTO_THREAD_lock_new()
    17.   # endif
    18.   
    19. > CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
    20.   {
    21.   # ifdef USE_RWLOCK

crypto/threads_pthread.c:22:5: 
    20.   {
    21.   # ifdef USE_RWLOCK
    22. >     CRYPTO_RWLOCK *lock = OPENSSL_zalloc(sizeof(pthread_rwlock_t));
    23.       if (lock == NULL)
    24.           return NULL;

crypto/mem.c:218:1: start of procedure CRYPTO_zalloc()
      216.   }
      217.   
      218. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
      219.   {
      220.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:220:5: 
      218.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
      219.   {
      220. >     void *ret = CRYPTO_malloc(num, file, line);
      221.   
      222.       FAILTEST();

crypto/mem.c:189:1: start of procedure CRYPTO_malloc()
        187.   #endif
        188.   
        189. > void *CRYPTO_malloc(size_t num, const char *file, int line)
        190.   {
        191.       void *ret = NULL;

crypto/mem.c:191:5: 
        189.   void *CRYPTO_malloc(size_t num, const char *file, int line)
        190.   {
        191. >     void *ret = NULL;
        192.   
        193.       INCREMENT(malloc_count);

crypto/mem.c:194:9: Taking true branch
        192.   
        193.       INCREMENT(malloc_count);
        194.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                       ^
        195.           return malloc_impl(num, file, line);
        196.   

crypto/mem.c:194:32: Taking true branch
        192.   
        193.       INCREMENT(malloc_count);
        194.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                                              ^
        195.           return malloc_impl(num, file, line);
        196.   

crypto/mem.c:195:9: Skipping __function_pointer__(): unresolved function pointer
        193.       INCREMENT(malloc_count);
        194.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
        195.           return malloc_impl(num, file, line);
                       ^
        196.   
        197.       if (num == 0)

crypto/mem.c:216:1: return from a call to CRYPTO_malloc
        214.   
        215.       return ret;
        216. > }
        217.   
        218.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:223:9: Taking true branch
      221.   
      222.       FAILTEST();
      223.       if (ret != NULL)
                     ^
      224.           memset(ret, 0, num);
      225.       return ret;

crypto/mem.c:224:9: 
      222.       FAILTEST();
      223.       if (ret != NULL)
      224. >         memset(ret, 0, num);
      225.       return ret;
      226.   }

crypto/mem.c:225:5: 
      223.       if (ret != NULL)
      224.           memset(ret, 0, num);
      225. >     return ret;
      226.   }
      227.   

crypto/mem.c:226:1: return from a call to CRYPTO_zalloc
      224.           memset(ret, 0, num);
      225.       return ret;
      226. > }
      227.   
      228.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/threads_pthread.c:23:9: Taking false branch
    21.   # ifdef USE_RWLOCK
    22.       CRYPTO_RWLOCK *lock = OPENSSL_zalloc(sizeof(pthread_rwlock_t));
    23.       if (lock == NULL)
                  ^
    24.           return NULL;
    25.   

crypto/threads_pthread.c:26:9: Taking true branch
    24.           return NULL;
    25.   
    26.       if (pthread_rwlock_init(lock, NULL) != 0) {
                  ^
    27.           OPENSSL_free(lock);
    28.           return NULL;

crypto/threads_pthread.c:27:9: 
    25.   
    26.       if (pthread_rwlock_init(lock, NULL) != 0) {
    27. >         OPENSSL_free(lock);
    28.           return NULL;
    29.       }

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

crypto/mem.c:289:9: Taking false branch
      287.   {
      288.       INCREMENT(free_count);
      289.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                     ^
      290.           free_impl(str, file, line);
      291.           return;

crypto/mem.c:303:5: 
      301.       }
      302.   #else
      303. >     free(str);
      304.   #endif
      305.   }

crypto/mem.c:305:1: return from a call to CRYPTO_free
      303.       free(str);
      304.   #endif
      305. > }
      306.   
      307.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/threads_pthread.c:28:9: 
    26.       if (pthread_rwlock_init(lock, NULL) != 0) {
    27.           OPENSSL_free(lock);
    28. >         return NULL;
    29.       }
    30.   # else

crypto/threads_pthread.c:49:1: return from a call to CRYPTO_THREAD_lock_new
    47.   
    48.       return lock;
    49. > }
    50.   
    51.   int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock)

crypto/init.c:735:9: Taking true branch
  733.       if ((newlock = malloc(sizeof(*newlock))) == NULL)
  734.           return NULL;
  735.       if ((newlock->lock = CRYPTO_THREAD_lock_new()) == NULL) {
                 ^
  736.           free(newlock);
  737.           return NULL;

crypto/init.c:736:9: 
  734.           return NULL;
  735.       if ((newlock->lock = CRYPTO_THREAD_lock_new()) == NULL) {
  736. >         free(newlock);
  737.           return NULL;
  738.       }

crypto/init.c:737:9: 
  735.       if ((newlock->lock = CRYPTO_THREAD_lock_new()) == NULL) {
  736.           free(newlock);
  737. >         return NULL;
  738.       }
  739.       newlock->name = name;

crypto/init.c:745:1: return from a call to CRYPTO_THREAD_glock_new
  743.       CRYPTO_THREAD_unlock(glock_lock);
  744.       return newlock->lock;
  745. > }
  746.   
  747.   /*

crypto/rand/drbg_lib.c:649:9: Taking true branch
647.   
648.       drbg->lock = CRYPTO_THREAD_glock_new(name);
649.       if (drbg->lock == NULL) {
               ^
650.           RANDerr(RAND_F_DRBG_SETUP, RAND_R_FAILED_TO_CREATE_LOCK);
651.           goto err;

crypto/rand/drbg_lib.c:650:9: Skipping ERR_put_error(): empty list of specs
648.       drbg->lock = CRYPTO_THREAD_glock_new(name);
649.       if (drbg->lock == NULL) {
650.           RANDerr(RAND_F_DRBG_SETUP, RAND_R_FAILED_TO_CREATE_LOCK);
               ^
651.           goto err;
652.       }

crypto/rand/drbg_lib.c:684:1: 
682.       return drbg;
683.   
684. > err:
685.       drbg_cleanup(drbg);
686.       return NULL;

crypto/rand/drbg_lib.c:685:5: Skipping drbg_cleanup(): empty list of specs
683.   
684.   err:
685.       drbg_cleanup(drbg);
           ^
686.       return NULL;
687.   }

static RAND_DRBG *drbg_setup(const char *name, RAND_DRBG *parent)
{
    RAND_DRBG *drbg;
    if (name == NULL) {
        RANDerr(RAND_F_DRBG_SETUP, ERR_R_INTERNAL_ERROR);
        return NULL;
    }
    drbg = OPENSSL_secure_zalloc(sizeof(RAND_DRBG));
    if (drbg == NULL)
        return NULL;
    drbg->lock = CRYPTO_THREAD_glock_new(name);
    if (drbg->lock == NULL) {
        RANDerr(RAND_F_DRBG_SETUP, RAND_R_FAILED_TO_CREATE_LOCK);
        goto err;
    }
    if (RAND_DRBG_set(drbg,
                      RAND_DRBG_NID, RAND_DRBG_FLAG_CTR_USE_DF) != 1)
        goto err;
    if (RAND_DRBG_set_callbacks(drbg, rand_drbg_get_entropy,
                                rand_drbg_cleanup_entropy, NULL, NULL) != 1)
        goto err;
    if (parent == NULL) {
        drbg->reseed_interval = MASTER_RESEED_INTERVAL;
        drbg->reseed_time_interval = MASTER_RESEED_TIME_INTERVAL;
    } else {
        drbg->parent = parent;
        drbg->reseed_interval = SLAVE_RESEED_INTERVAL;
        drbg->reseed_time_interval = SLAVE_RESEED_TIME_INTERVAL;
    }
    drbg->reseed_counter = 1;
    RAND_DRBG_instantiate(drbg,
                          (const unsigned char *) ossl_pers_string,
                          sizeof(ossl_pers_string) - 1);
    return drbg;
err:
    drbg_cleanup(drbg);
    return NULL;
}
['static RAND_DRBG *drbg_setup(const char *name, RAND_DRBG *parent)\n{\n    RAND_DRBG *drbg;\n    if (name == NULL) {\n        RANDerr(RAND_F_DRBG_SETUP, ERR_R_INTERNAL_ERROR);\n        return NULL;\n    }\n    drbg = OPENSSL_secure_zalloc(sizeof(RAND_DRBG));\n    if (drbg == NULL)\n        return NULL;\n    drbg->lock = CRYPTO_THREAD_glock_new(name);\n    if (drbg->lock == NULL) {\n        RANDerr(RAND_F_DRBG_SETUP, RAND_R_FAILED_TO_CREATE_LOCK);\n        goto err;\n    }\n    if (RAND_DRBG_set(drbg,\n                      RAND_DRBG_NID, RAND_DRBG_FLAG_CTR_USE_DF) != 1)\n        goto err;\n    if (RAND_DRBG_set_callbacks(drbg, rand_drbg_get_entropy,\n                                rand_drbg_cleanup_entropy, NULL, NULL) != 1)\n        goto err;\n    if (parent == NULL) {\n        drbg->reseed_interval = MASTER_RESEED_INTERVAL;\n        drbg->reseed_time_interval = MASTER_RESEED_TIME_INTERVAL;\n    } else {\n        drbg->parent = parent;\n        drbg->reseed_interval = SLAVE_RESEED_INTERVAL;\n        drbg->reseed_time_interval = SLAVE_RESEED_TIME_INTERVAL;\n    }\n    drbg->reseed_counter = 1;\n    RAND_DRBG_instantiate(drbg,\n                          (const unsigned char *) ossl_pers_string,\n                          sizeof(ossl_pers_string) - 1);\n    return drbg;\nerr:\n    drbg_cleanup(drbg);\n    return NULL;\n}', 'void *CRYPTO_secure_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_secure_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_secure_malloc(size_t num, const char *file, int line)\n{\n#ifdef IMPLEMENTED\n    void *ret;\n    size_t actual_size;\n    if (!secure_mem_initialized) {\n        return CRYPTO_malloc(num, file, line);\n    }\n    CRYPTO_THREAD_write_lock(sec_malloc_lock);\n    ret = sh_malloc(num);\n    actual_size = ret ? sh_actual_size(ret) : 0;\n    secure_mem_used += actual_size;\n    CRYPTO_THREAD_unlock(sec_malloc_lock);\n    return ret;\n#else\n    return CRYPTO_malloc(num, file, line);\n#endif\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    INCREMENT(malloc_count);\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\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    (void)(file); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}', 'CRYPTO_RWLOCK *CRYPTO_THREAD_glock_new(const char *name)\n{\n    GLOBAL_LOCK *newlock;\n    if (glock_lock == NULL && !RUN_ONCE(&glock_once, glock_init))\n        return NULL;\n    if ((newlock = malloc(sizeof(*newlock))) == NULL)\n        return NULL;\n    if ((newlock->lock = CRYPTO_THREAD_lock_new()) == NULL) {\n        free(newlock);\n        return NULL;\n    }\n    newlock->name = name;\n    CRYPTO_THREAD_write_lock(glock_lock);\n    newlock->next = global_locks;\n    global_locks = newlock;\n    CRYPTO_THREAD_unlock(glock_lock);\n    return newlock->lock;\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}', 'CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)\n{\n# ifdef USE_RWLOCK\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# else\n    pthread_mutexattr_t attr;\n    CRYPTO_RWLOCK *lock = OPENSSL_zalloc(sizeof(pthread_mutex_t));\n    if (lock == NULL)\n        return NULL;\n    pthread_mutexattr_init(&attr);\n    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);\n    if (pthread_mutex_init(lock, &attr) != 0) {\n        pthread_mutexattr_destroy(&attr);\n        OPENSSL_free(lock);\n        return NULL;\n    }\n    pthread_mutexattr_destroy(&attr);\n# endif\n    return lock;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    FAILTEST();\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\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}']