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}']