crypto/x509/x509_lu.c:354: error: MEMORY_LEAK
  memory dynamically allocated by call to `CRYPTO_malloc()` at line 335, column 11 is not reachable after line 354, column 9.
Showing all 61 steps of the trace


crypto/x509/x509_lu.c:328:1: start of procedure X509_STORE_add_cert()
326.   }
327.   
328. > int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
329.   {
330.       X509_OBJECT *obj;

crypto/x509/x509_lu.c:331:5: 
329.   {
330.       X509_OBJECT *obj;
331. >     int ret = 1;
332.   
333.       if (x == NULL)

crypto/x509/x509_lu.c:333:9: Taking false branch
331.       int ret = 1;
332.   
333.       if (x == NULL)
               ^
334.           return 0;
335.       obj = OPENSSL_malloc(sizeof(*obj));

crypto/x509/x509_lu.c:335:5: 
333.       if (x == NULL)
334.           return 0;
335. >     obj = OPENSSL_malloc(sizeof(*obj));
336.       if (obj == NULL) {
337.           X509err(X509_F_X509_STORE_ADD_CERT, ERR_R_MALLOC_FAILURE);

crypto/mem.c:120:1: start of procedure CRYPTO_malloc()
  118.   }
  119.   
  120. > void *CRYPTO_malloc(size_t num, const char *file, int line)
  121.   {
  122.       void *ret = NULL;

crypto/mem.c:122:5: 
  120.   void *CRYPTO_malloc(size_t num, const char *file, int line)
  121.   {
  122. >     void *ret = NULL;
  123.   
  124.       if (num <= 0)

crypto/mem.c:124:9: Taking false branch
  122.       void *ret = NULL;
  123.   
  124.       if (num <= 0)
                 ^
  125.           return NULL;
  126.   

crypto/mem.c:127:5: 
  125.           return NULL;
  126.   
  127. >     allow_customize = 0;
  128.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG
  129.       if (call_malloc_debug) {

crypto/mem.c:137:5: 
  135.       }
  136.   #else
  137. >     (void)file;
  138.       (void)line;
  139.       ret = malloc(num);

crypto/mem.c:138:5: 
  136.   #else
  137.       (void)file;
  138. >     (void)line;
  139.       ret = malloc(num);
  140.   #endif

crypto/mem.c:139:5: 
  137.       (void)file;
  138.       (void)line;
  139. >     ret = malloc(num);
  140.   #endif
  141.   

crypto/mem.c:154:5: 
  152.   #endif
  153.   
  154. >     return ret;
  155.   }
  156.   

crypto/mem.c:155:1: return from a call to CRYPTO_malloc
  153.   
  154.       return ret;
  155. > }
  156.   
  157.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/x509/x509_lu.c:336:9: Taking false branch
334.           return 0;
335.       obj = OPENSSL_malloc(sizeof(*obj));
336.       if (obj == NULL) {
               ^
337.           X509err(X509_F_X509_STORE_ADD_CERT, ERR_R_MALLOC_FAILURE);
338.           return 0;

crypto/x509/x509_lu.c:340:5: 
338.           return 0;
339.       }
340. >     obj->type = X509_LU_X509;
341.       obj->data.x509 = x;
342.   

crypto/x509/x509_lu.c:341:5: 
339.       }
340.       obj->type = X509_LU_X509;
341. >     obj->data.x509 = x;
342.   
343.       CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);

crypto/x509/x509_lu.c:343:5: 
341.       obj->data.x509 = x;
342.   
343. >     CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
344.   
345.       X509_OBJECT_up_ref_count(obj);

crypto/lock.c:414:1: start of procedure CRYPTO_lock()
  412.   }
  413.   
  414. > void CRYPTO_lock(int mode, int type, const char *file, int line)
  415.   {
  416.   #ifdef LOCK_DEBUG

crypto/lock.c:441:9: Taking false branch
  439.       }
  440.   #endif
  441.       if (type < 0) {
                 ^
  442.           if (dynlock_lock_callback != NULL) {
  443.               struct CRYPTO_dynlock_value *pointer

crypto/lock.c:452:16: Taking true branch
  450.               CRYPTO_destroy_dynlockid(type);
  451.           }
  452.       } else if (locking_callback != NULL)
                        ^
  453.           locking_callback(mode, type, file, line);
  454.   }

crypto/lock.c:453:9: Skipping __function_pointer__(): unresolved function pointer
  451.           }
  452.       } else if (locking_callback != NULL)
  453.           locking_callback(mode, type, file, line);
                 ^
  454.   }
  455.   

crypto/lock.c:441:5: 
  439.       }
  440.   #endif
  441. >     if (type < 0) {
  442.           if (dynlock_lock_callback != NULL) {
  443.               struct CRYPTO_dynlock_value *pointer

crypto/lock.c:454:1: return from a call to CRYPTO_lock
  452.       } else if (locking_callback != NULL)
  453.           locking_callback(mode, type, file, line);
  454. > }
  455.   
  456.   int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,

crypto/x509/x509_lu.c:345:5: 
343.       CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
344.   
345. >     X509_OBJECT_up_ref_count(obj);
346.   
347.       if (X509_OBJECT_retrieve_match(ctx->objs, obj)) {

crypto/x509/x509_lu.c:393:1: start of procedure X509_OBJECT_up_ref_count()
  391.   }
  392.   
  393. > void X509_OBJECT_up_ref_count(X509_OBJECT *a)
  394.   {
  395.       switch (a->type) {

crypto/x509/x509_lu.c:395:5: 
  393.   void X509_OBJECT_up_ref_count(X509_OBJECT *a)
  394.   {
  395. >     switch (a->type) {
  396.       default:
  397.           break;

crypto/x509/x509_lu.c:398:5: Switch condition is true. Entering switch case
  396.       default:
  397.           break;
  398.       case X509_LU_X509:
             ^
  399.           X509_up_ref(a->data.x509);
  400.           break;

crypto/x509/x509_lu.c:399:9: 
  397.           break;
  398.       case X509_LU_X509:
  399. >         X509_up_ref(a->data.x509);
  400.           break;
  401.       case X509_LU_CRL:

crypto/x509/x509_set.c:150:1: start of procedure X509_up_ref()
    148.   }
    149.   
    150. > void X509_up_ref(X509 *x)
    151.   {
    152.       CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);

crypto/x509/x509_set.c:152:5: 
    150.   void X509_up_ref(X509 *x)
    151.   {
    152. >     CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
    153.   }
    154.   

crypto/lock.c:456:1: start of procedure CRYPTO_add_lock()
      454.   }
      455.   
      456. > int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
      457.                       int line)
      458.   {

crypto/lock.c:459:5: 
      457.                       int line)
      458.   {
      459. >     int ret = 0;
      460.   
      461.       if (add_lock_callback != NULL) {

crypto/lock.c:461:9: Taking true branch
      459.       int ret = 0;
      460.   
      461.       if (add_lock_callback != NULL) {
                     ^
      462.   #ifdef LOCK_DEBUG
      463.           int before = *pointer;

crypto/lock.c:466:9: Skipping __function_pointer__(): unresolved function pointer
      464.   #endif
      465.   
      466.           ret = add_lock_callback(pointer, amount, type, file, line);
                     ^
      467.   #ifdef LOCK_DEBUG
      468.           {

crypto/lock.c:493:5: 
      491.           CRYPTO_lock(CRYPTO_UNLOCK | CRYPTO_WRITE, type, file, line);
      492.       }
      493. >     return (ret);
      494.   }
      495.   

crypto/lock.c:494:1: return from a call to CRYPTO_add_lock
      492.       }
      493.       return (ret);
      494. > }
      495.   
      496.   const char *CRYPTO_get_lock_name(int type)

crypto/x509/x509_set.c:153:1: return from a call to X509_up_ref
    151.   {
    152.       CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
    153. > }
    154.   
    155.   long X509_get_version(X509 *x)

crypto/x509/x509_lu.c:405:1: return from a call to X509_OBJECT_up_ref_count
  403.           break;
  404.       }
  405. > }
  406.   
  407.   void X509_OBJECT_free_contents(X509_OBJECT *a)

crypto/x509/x509_lu.c:347:9: Taking false branch
345.       X509_OBJECT_up_ref_count(obj);
346.   
347.       if (X509_OBJECT_retrieve_match(ctx->objs, obj)) {
               ^
348.           X509_OBJECT_free_contents(obj);
349.           OPENSSL_free(obj);

crypto/x509/x509_lu.c:354:9: 
352.           ret = 0;
353.       } else
354. >         sk_X509_OBJECT_push(ctx->objs, obj);
355.   
356.       CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);

include/openssl/x509_vfy.h:124:1: start of procedure sk_X509_OBJECT_push()
  122.   
  123.   DEFINE_STACK_OF(X509_LOOKUP)
  124. > DEFINE_STACK_OF(X509_OBJECT)
  125.   
  126.   /* This is a static that defines the function interface */

crypto/stack/stack.c:259:1: start of procedure sk_push()
    257.   }
    258.   
    259. > int sk_push(_STACK *st, void *data)
    260.   {
    261.       return (sk_insert(st, data, st->num));

crypto/stack/stack.c:261:5: 
    259.   int sk_push(_STACK *st, void *data)
    260.   {
    261. >     return (sk_insert(st, data, st->num));
    262.   }
    263.   

crypto/stack/stack.c:167:1: start of procedure sk_insert()
      165.   }
      166.   
      167. > int sk_insert(_STACK *st, void *data, int loc)
      168.   {
      169.       char **s;

crypto/stack/stack.c:171:9: Taking false branch
      169.       char **s;
      170.   
      171.       if (st == NULL)
                     ^
      172.           return 0;
      173.       if (st->num_alloc <= st->num + 1) {

crypto/stack/stack.c:173:9: Taking true branch
      171.       if (st == NULL)
      172.           return 0;
      173.       if (st->num_alloc <= st->num + 1) {
                     ^
      174.           s = OPENSSL_realloc((char *)st->data,
      175.                               (unsigned int)sizeof(char *) * st->num_alloc * 2);

crypto/stack/stack.c:174:9: 
      172.           return 0;
      173.       if (st->num_alloc <= st->num + 1) {
      174. >         s = OPENSSL_realloc((char *)st->data,
      175.                               (unsigned int)sizeof(char *) * st->num_alloc * 2);
      176.           if (s == NULL)

crypto/mem.c:166:1: start of procedure CRYPTO_realloc()
        164.   }
        165.   
        166. > void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)
        167.   {
        168.       if (str == NULL)

crypto/mem.c:168:9: Taking true branch
        166.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)
        167.   {
        168.       if (str == NULL)
                       ^
        169.           return CRYPTO_malloc(num, file, line);
        170.   

crypto/mem.c:169:9: 
        167.   {
        168.       if (str == NULL)
        169. >         return CRYPTO_malloc(num, file, line);
        170.   
        171.       if (num == 0) {

crypto/mem.c:120:1: start of procedure CRYPTO_malloc()
          118.   }
          119.   
          120. > void *CRYPTO_malloc(size_t num, const char *file, int line)
          121.   {
          122.       void *ret = NULL;

crypto/mem.c:122:5: 
          120.   void *CRYPTO_malloc(size_t num, const char *file, int line)
          121.   {
          122. >     void *ret = NULL;
          123.   
          124.       if (num <= 0)

crypto/mem.c:124:9: Taking true branch
          122.       void *ret = NULL;
          123.   
          124.       if (num <= 0)
                         ^
          125.           return NULL;
          126.   

crypto/mem.c:125:9: 
          123.   
          124.       if (num <= 0)
          125. >         return NULL;
          126.   
          127.       allow_customize = 0;

crypto/mem.c:155:1: return from a call to CRYPTO_malloc
          153.   
          154.       return ret;
          155. > }
          156.   
          157.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem.c:191:1: return from a call to CRYPTO_realloc
        189.       return realloc(str, num);
        190.   
        191. > }
        192.   
        193.   void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,

crypto/stack/stack.c:176:13: Taking true branch
      174.           s = OPENSSL_realloc((char *)st->data,
      175.                               (unsigned int)sizeof(char *) * st->num_alloc * 2);
      176.           if (s == NULL)
                         ^
      177.               return (0);
      178.           st->data = s;

crypto/stack/stack.c:177:13: 
      175.                               (unsigned int)sizeof(char *) * st->num_alloc * 2);
      176.           if (s == NULL)
      177. >             return (0);
      178.           st->data = s;
      179.           st->num_alloc *= 2;

crypto/stack/stack.c:191:1: return from a call to sk_insert
      189.       st->sorted = 0;
      190.       return (st->num);
      191. > }
      192.   
      193.   void *sk_delete_ptr(_STACK *st, void *p)

crypto/stack/stack.c:262:1: return from a call to sk_push
    260.   {
    261.       return (sk_insert(st, data, st->num));
    262. > }
    263.   
    264.   int sk_unshift(_STACK *st, void *data)

include/openssl/x509_vfy.h:124:1: return from a call to sk_X509_OBJECT_push
  122.   
  123.   DEFINE_STACK_OF(X509_LOOKUP)
  124. > DEFINE_STACK_OF(X509_OBJECT)
  125.   
  126.   /* This is a static that defines the function interface */

int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
{
    X509_OBJECT *obj;
    int ret = 1;
    if (x == NULL)
        return 0;
    obj = OPENSSL_malloc(sizeof(*obj));
    if (obj == NULL) {
        X509err(X509_F_X509_STORE_ADD_CERT, ERR_R_MALLOC_FAILURE);
        return 0;
    }
    obj->type = X509_LU_X509;
    obj->data.x509 = x;
    CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
    X509_OBJECT_up_ref_count(obj);
    if (X509_OBJECT_retrieve_match(ctx->objs, obj)) {
        X509_OBJECT_free_contents(obj);
        OPENSSL_free(obj);
        X509err(X509_F_X509_STORE_ADD_CERT,
                X509_R_CERT_ALREADY_IN_HASH_TABLE);
        ret = 0;
    } else
        sk_X509_OBJECT_push(ctx->objs, obj);
    CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
    return ret;
}
['int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)\n{\n    X509_OBJECT *obj;\n    int ret = 1;\n    if (x == NULL)\n        return 0;\n    obj = OPENSSL_malloc(sizeof(*obj));\n    if (obj == NULL) {\n        X509err(X509_F_X509_STORE_ADD_CERT, ERR_R_MALLOC_FAILURE);\n        return 0;\n    }\n    obj->type = X509_LU_X509;\n    obj->data.x509 = x;\n    CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);\n    X509_OBJECT_up_ref_count(obj);\n    if (X509_OBJECT_retrieve_match(ctx->objs, obj)) {\n        X509_OBJECT_free_contents(obj);\n        OPENSSL_free(obj);\n        X509err(X509_F_X509_STORE_ADD_CERT,\n                X509_R_CERT_ALREADY_IN_HASH_TABLE);\n        ret = 0;\n    } else\n        sk_X509_OBJECT_push(ctx->objs, obj);\n    CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\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    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n{\n#ifdef LOCK_DEBUG\n    {\n        CRYPTO_THREADID id;\n        char *rw_text, *operation_text;\n        if (mode & CRYPTO_LOCK)\n            operation_text = "lock  ";\n        else if (mode & CRYPTO_UNLOCK)\n            operation_text = "unlock";\n        else\n            operation_text = "ERROR ";\n        if (mode & CRYPTO_READ)\n            rw_text = "r";\n        else if (mode & CRYPTO_WRITE)\n            rw_text = "w";\n        else\n            rw_text = "ERROR";\n        CRYPTO_THREADID_current(&id);\n        fprintf(stderr, "lock:%08lx:(%s)%s %-18s %s:%d\\n",\n                CRYPTO_THREADID_hash(&id), rw_text, operation_text,\n                CRYPTO_get_lock_name(type), file, line);\n    }\n#endif\n    if (type < 0) {\n        if (dynlock_lock_callback != NULL) {\n            struct CRYPTO_dynlock_value *pointer\n                = CRYPTO_get_dynlock_value(type);\n            OPENSSL_assert(pointer != NULL);\n            dynlock_lock_callback(mode, pointer, file, line);\n            CRYPTO_destroy_dynlockid(type);\n        }\n    } else if (locking_callback != NULL)\n        locking_callback(mode, type, file, line);\n}', 'void X509_OBJECT_up_ref_count(X509_OBJECT *a)\n{\n    switch (a->type) {\n    default:\n        break;\n    case X509_LU_X509:\n        X509_up_ref(a->data.x509);\n        break;\n    case X509_LU_CRL:\n        X509_CRL_up_ref(a->data.crl);\n        break;\n    }\n}', 'void X509_up_ref(X509 *x)\n{\n    CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);\n}', 'int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,\n                    int line)\n{\n    int ret = 0;\n    if (add_lock_callback != NULL) {\n#ifdef LOCK_DEBUG\n        int before = *pointer;\n#endif\n        ret = add_lock_callback(pointer, amount, type, file, line);\n#ifdef LOCK_DEBUG\n        {\n            CRYPTO_THREADID id;\n            CRYPTO_THREADID_current(&id);\n            fprintf(stderr, "ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n                    CRYPTO_THREADID_hash(&id), before, amount, ret,\n                    CRYPTO_get_lock_name(type), file, line);\n        }\n#endif\n    } else {\n        CRYPTO_lock(CRYPTO_LOCK | CRYPTO_WRITE, type, file, line);\n        ret = *pointer + amount;\n#ifdef LOCK_DEBUG\n        {\n            CRYPTO_THREADID id;\n            CRYPTO_THREADID_current(&id);\n            fprintf(stderr, "ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n                    CRYPTO_THREADID_hash(&id),\n                    *pointer, amount, ret,\n                    CRYPTO_get_lock_name(type), file, line);\n        }\n#endif\n        *pointer = ret;\n        CRYPTO_lock(CRYPTO_UNLOCK | CRYPTO_WRITE, type, file, line);\n    }\n    return (ret);\n}', 'int sk_push(_STACK *st, void *data)\n{\n    return (sk_insert(st, data, st->num));\n}', 'int sk_insert(_STACK *st, void *data, int loc)\n{\n    char **s;\n    if (st == NULL)\n        return 0;\n    if (st->num_alloc <= st->num + 1) {\n        s = OPENSSL_realloc((char *)st->data,\n                            (unsigned int)sizeof(char *) * st->num_alloc * 2);\n        if (s == NULL)\n            return (0);\n        st->data = s;\n        st->num_alloc *= 2;\n    }\n    if ((loc >= (int)st->num) || (loc < 0))\n        st->data[st->num] = data;\n    else {\n        memmove(&(st->data[loc + 1]),\n                &(st->data[loc]), sizeof(char *) * (st->num - loc));\n        st->data[loc] = data;\n    }\n    st->num++;\n    st->sorted = 0;\n    return (st->num);\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n    if (str == NULL)\n        return CRYPTO_malloc(num, file, line);\n    if (num == 0) {\n        CRYPTO_free(str);\n        return NULL;\n    }\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        void *ret;\n        CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n        ret = realloc(str, num);\n        CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n        return ret;\n    }\n#else\n    (void)file;\n    (void)line;\n#endif\n    return realloc(str, num);\n}']