crypto/initthread.c:372: error: NULL_DEREFERENCE
  pointer `gtr` last assigned on line 370 could be null and is dereferenced at line 372, column 34.
Showing all 14 steps of the trace


crypto/initthread.c:365:1: start of procedure init_thread_deregister()
363.   
364.   #ifndef FIPS_MODE
365. > static int init_thread_deregister(void *index, int all)
366.   {
367.       GLOBAL_TEVENT_REGISTER *gtr;

crypto/initthread.c:370:5: 
368.       int i;
369.   
370. >     gtr = get_global_tevent_register();
371.       if (!all)
372.           CRYPTO_THREAD_write_lock(gtr->lock);

crypto/initthread.c:72:1: start of procedure get_global_tevent_register()
  70.   }
  71.   
  72. > static GLOBAL_TEVENT_REGISTER *get_global_tevent_register(void)
  73.   {
  74.       if (!RUN_ONCE(&tevent_register_runonce, create_global_tevent_register))

crypto/initthread.c:74:10: 
  72.   static GLOBAL_TEVENT_REGISTER *get_global_tevent_register(void)
  73.   {
  74. >     if (!RUN_ONCE(&tevent_register_runonce, create_global_tevent_register))
  75.           return NULL;
  76.       return glob_tevent_reg;

crypto/threads_pthread.c:111:1: start of procedure CRYPTO_THREAD_run_once()
    109.   }
    110.   
    111. > int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
    112.   {
    113.       if (pthread_once(once, init) != 0)

crypto/threads_pthread.c:113:9: Taking true branch
    111.   int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
    112.   {
    113.       if (pthread_once(once, init) != 0)
                   ^
    114.           return 0;
    115.   

crypto/threads_pthread.c:114:9: 
    112.   {
    113.       if (pthread_once(once, init) != 0)
    114. >         return 0;
    115.   
    116.       return 1;

crypto/threads_pthread.c:117:1: return from a call to CRYPTO_THREAD_run_once
    115.   
    116.       return 1;
    117. > }
    118.   
    119.   int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *))

crypto/initthread.c:74:10: Condition is false
  72.   static GLOBAL_TEVENT_REGISTER *get_global_tevent_register(void)
  73.   {
  74.       if (!RUN_ONCE(&tevent_register_runonce, create_global_tevent_register))
                 ^
  75.           return NULL;
  76.       return glob_tevent_reg;

crypto/initthread.c:74:10: Taking true branch
  72.   static GLOBAL_TEVENT_REGISTER *get_global_tevent_register(void)
  73.   {
  74.       if (!RUN_ONCE(&tevent_register_runonce, create_global_tevent_register))
                 ^
  75.           return NULL;
  76.       return glob_tevent_reg;

crypto/initthread.c:75:9: 
  73.   {
  74.       if (!RUN_ONCE(&tevent_register_runonce, create_global_tevent_register))
  75. >         return NULL;
  76.       return glob_tevent_reg;
  77.   }

crypto/initthread.c:77:1: return from a call to get_global_tevent_register
  75.           return NULL;
  76.       return glob_tevent_reg;
  77. > }
  78.   #endif
  79.   

crypto/initthread.c:371:10: Taking true branch
369.   
370.       gtr = get_global_tevent_register();
371.       if (!all)
                ^
372.           CRYPTO_THREAD_write_lock(gtr->lock);
373.       for (i = 0; i < sk_THREAD_EVENT_HANDLER_PTR_num(gtr->skhands); i++) {

crypto/initthread.c:372:9: 
370.       gtr = get_global_tevent_register();
371.       if (!all)
372. >         CRYPTO_THREAD_write_lock(gtr->lock);
373.       for (i = 0; i < sk_THREAD_EVENT_HANDLER_PTR_num(gtr->skhands); i++) {
374.           THREAD_EVENT_HANDLER **hands

static int init_thread_deregister(void *index, int all)
{
    GLOBAL_TEVENT_REGISTER *gtr;
    int i;
    gtr = get_global_tevent_register();
    if (!all)
        CRYPTO_THREAD_write_lock(gtr->lock);
    for (i = 0; i < sk_THREAD_EVENT_HANDLER_PTR_num(gtr->skhands); i++) {
        THREAD_EVENT_HANDLER **hands
            = sk_THREAD_EVENT_HANDLER_PTR_value(gtr->skhands, i);
        THREAD_EVENT_HANDLER *curr = *hands, *prev = NULL, *tmp;
        if (hands == NULL) {
            if (!all)
                CRYPTO_THREAD_unlock(gtr->lock);
            return 0;
        }
        while (curr != NULL) {
            if (all || curr->index == index) {
                if (prev != NULL)
                    prev->next = curr->next;
                else
                    *hands = curr->next;
                tmp = curr;
                curr = curr->next;
                OPENSSL_free(tmp);
                continue;
            }
            prev = curr;
            curr = curr->next;
        }
        if (all)
            OPENSSL_free(hands);
    }
    if (all) {
        CRYPTO_THREAD_lock_free(gtr->lock);
        sk_THREAD_EVENT_HANDLER_PTR_free(gtr->skhands);
        OPENSSL_free(gtr);
    } else {
        CRYPTO_THREAD_unlock(gtr->lock);
    }
    return 1;
}
['static int init_thread_deregister(void *index, int all)\n{\n    GLOBAL_TEVENT_REGISTER *gtr;\n    int i;\n    gtr = get_global_tevent_register();\n    if (!all)\n        CRYPTO_THREAD_write_lock(gtr->lock);\n    for (i = 0; i < sk_THREAD_EVENT_HANDLER_PTR_num(gtr->skhands); i++) {\n        THREAD_EVENT_HANDLER **hands\n            = sk_THREAD_EVENT_HANDLER_PTR_value(gtr->skhands, i);\n        THREAD_EVENT_HANDLER *curr = *hands, *prev = NULL, *tmp;\n        if (hands == NULL) {\n            if (!all)\n                CRYPTO_THREAD_unlock(gtr->lock);\n            return 0;\n        }\n        while (curr != NULL) {\n            if (all || curr->index == index) {\n                if (prev != NULL)\n                    prev->next = curr->next;\n                else\n                    *hands = curr->next;\n                tmp = curr;\n                curr = curr->next;\n                OPENSSL_free(tmp);\n                continue;\n            }\n            prev = curr;\n            curr = curr->next;\n        }\n        if (all)\n            OPENSSL_free(hands);\n    }\n    if (all) {\n        CRYPTO_THREAD_lock_free(gtr->lock);\n        sk_THREAD_EVENT_HANDLER_PTR_free(gtr->skhands);\n        OPENSSL_free(gtr);\n    } else {\n        CRYPTO_THREAD_unlock(gtr->lock);\n    }\n    return 1;\n}', 'static GLOBAL_TEVENT_REGISTER *get_global_tevent_register(void)\n{\n    if (!RUN_ONCE(&tevent_register_runonce, create_global_tevent_register))\n        return NULL;\n    return glob_tevent_reg;\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}']