crypto/dh/dh_check.c:161: error: MEMORY_LEAK
  memory dynamically allocated by call to `BN_new()` at line 148, column 9 is not reachable after line 161, column 5.
Showing all 56 steps of the trace


crypto/dh/dh_check.c:142:1: start of procedure DH_check_pub_key()
140.   }
141.   
142. > int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
143.   {
144.       int ok = 0;

crypto/dh/dh_check.c:144:5: 
142.   int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
143.   {
144. >     int ok = 0;
145.       BIGNUM *q = NULL;
146.   

crypto/dh/dh_check.c:145:5: 
143.   {
144.       int ok = 0;
145. >     BIGNUM *q = NULL;
146.   
147.       *ret = 0;

crypto/dh/dh_check.c:147:5: 
145.       BIGNUM *q = NULL;
146.   
147. >     *ret = 0;
148.       q = BN_new();
149.       if (q == NULL)

crypto/dh/dh_check.c:148:5: 
146.   
147.       *ret = 0;
148. >     q = BN_new();
149.       if (q == NULL)
150.           goto err;

crypto/bn/bn_lib.c:276:1: start of procedure BN_new()
  274.   }
  275.   
  276. > BIGNUM *BN_new(void)
  277.   {
  278.       BIGNUM *ret;

crypto/bn/bn_lib.c:280:9: 
  278.       BIGNUM *ret;
  279.   
  280. >     if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
  281.           BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);
  282.           return (NULL);

crypto/mem.c:156:1: start of procedure CRYPTO_zalloc()
    154.   }
    155.   
    156. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:158:5: 
    156.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
    157.   {
    158. >     void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       if (ret != NULL)

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

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

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

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

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

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

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

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

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

crypto/mem.c:160:9: Taking true branch
    158.       void *ret = CRYPTO_malloc(num, file, line);
    159.   
    160.       if (ret != NULL)
                   ^
    161.           memset(ret, 0, num);
    162.       return ret;

crypto/mem.c:161:9: 
    159.   
    160.       if (ret != NULL)
    161. >         memset(ret, 0, num);
    162.       return ret;
    163.   }

crypto/mem.c:162:5: 
    160.       if (ret != NULL)
    161.           memset(ret, 0, num);
    162. >     return ret;
    163.   }
    164.   

crypto/mem.c:163:1: return from a call to CRYPTO_zalloc
    161.           memset(ret, 0, num);
    162.       return ret;
    163. > }
    164.   
    165.   void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)

crypto/bn/bn_lib.c:280:9: Taking false branch
  278.       BIGNUM *ret;
  279.   
  280.       if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
                 ^
  281.           BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);
  282.           return (NULL);

crypto/bn/bn_lib.c:284:5: 
  282.           return (NULL);
  283.       }
  284. >     ret->flags = BN_FLG_MALLOCED;
  285.       bn_check_top(ret);
  286.       return (ret);

crypto/bn/bn_lib.c:286:5: 
  284.       ret->flags = BN_FLG_MALLOCED;
  285.       bn_check_top(ret);
  286. >     return (ret);
  287.   }
  288.   

crypto/bn/bn_lib.c:287:1: return from a call to BN_new
  285.       bn_check_top(ret);
  286.       return (ret);
  287. > }
  288.   
  289.    BIGNUM *BN_secure_new(void)

crypto/dh/dh_check.c:149:9: Taking false branch
147.       *ret = 0;
148.       q = BN_new();
149.       if (q == NULL)
               ^
150.           goto err;
151.       BN_set_word(q, 1);

crypto/dh/dh_check.c:151:5: 
149.       if (q == NULL)
150.           goto err;
151. >     BN_set_word(q, 1);
152.       if (BN_cmp(pub_key, q) <= 0)
153.           *ret |= DH_CHECK_PUBKEY_TOO_SMALL;

crypto/bn/bn_lib.c:529:1: start of procedure BN_set_word()
  527.   }
  528.   
  529. > int BN_set_word(BIGNUM *a, BN_ULONG w)
  530.   {
  531.       bn_check_top(a);

crypto/bn/bn_lib.c:532:9: Condition is true
  530.   {
  531.       bn_check_top(a);
  532.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                 ^
  533.           return (0);
  534.       a->neg = 0;

crypto/bn/bn_lib.c:532:9: Taking false branch
  530.   {
  531.       bn_check_top(a);
  532.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                 ^
  533.           return (0);
  534.       a->neg = 0;

crypto/bn/bn_lib.c:534:5: 
  532.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
  533.           return (0);
  534. >     a->neg = 0;
  535.       a->d[0] = w;
  536.       a->top = (w ? 1 : 0);

crypto/bn/bn_lib.c:535:5: 
  533.           return (0);
  534.       a->neg = 0;
  535. >     a->d[0] = w;
  536.       a->top = (w ? 1 : 0);
  537.       bn_check_top(a);

crypto/bn/bn_lib.c:536:15: Condition is true
  534.       a->neg = 0;
  535.       a->d[0] = w;
  536.       a->top = (w ? 1 : 0);
                       ^
  537.       bn_check_top(a);
  538.       return (1);

crypto/bn/bn_lib.c:536:5: 
  534.       a->neg = 0;
  535.       a->d[0] = w;
  536. >     a->top = (w ? 1 : 0);
  537.       bn_check_top(a);
  538.       return (1);

crypto/bn/bn_lib.c:538:5: 
  536.       a->top = (w ? 1 : 0);
  537.       bn_check_top(a);
  538. >     return (1);
  539.   }
  540.   

crypto/bn/bn_lib.c:539:1: return from a call to BN_set_word
  537.       bn_check_top(a);
  538.       return (1);
  539. > }
  540.   
  541.   BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)

crypto/dh/dh_check.c:152:9: Taking false branch
150.           goto err;
151.       BN_set_word(q, 1);
152.       if (BN_cmp(pub_key, q) <= 0)
               ^
153.           *ret |= DH_CHECK_PUBKEY_TOO_SMALL;
154.       BN_copy(q, dh->p);

crypto/dh/dh_check.c:154:5: Skipping BN_copy(): empty list of specs
152.       if (BN_cmp(pub_key, q) <= 0)
153.           *ret |= DH_CHECK_PUBKEY_TOO_SMALL;
154.       BN_copy(q, dh->p);
           ^
155.       BN_sub_word(q, 1);
156.       if (BN_cmp(pub_key, q) >= 0)

crypto/dh/dh_check.c:155:5: Skipping BN_sub_word(): empty list of specs
153.           *ret |= DH_CHECK_PUBKEY_TOO_SMALL;
154.       BN_copy(q, dh->p);
155.       BN_sub_word(q, 1);
           ^
156.       if (BN_cmp(pub_key, q) >= 0)
157.           *ret |= DH_CHECK_PUBKEY_TOO_LARGE;

crypto/dh/dh_check.c:156:9: Taking false branch
154.       BN_copy(q, dh->p);
155.       BN_sub_word(q, 1);
156.       if (BN_cmp(pub_key, q) >= 0)
               ^
157.           *ret |= DH_CHECK_PUBKEY_TOO_LARGE;
158.   

crypto/dh/dh_check.c:159:5: 
157.           *ret |= DH_CHECK_PUBKEY_TOO_LARGE;
158.   
159. >     ok = 1;
160.    err:
161.       BN_free(q);

crypto/dh/dh_check.c:160:2: 
158.   
159.       ok = 1;
160. >  err:
161.       BN_free(q);
162.       return (ok);

crypto/dh/dh_check.c:161:5: 
159.       ok = 1;
160.    err:
161. >     BN_free(q);
162.       return (ok);
163.   }

crypto/bn/bn_lib.c:251:1: start of procedure BN_free()
  249.   }
  250.   
  251. > void BN_free(BIGNUM *a)
  252.   {
  253.       if (a == NULL)

crypto/bn/bn_lib.c:253:9: Taking false branch
  251.   void BN_free(BIGNUM *a)
  252.   {
  253.       if (a == NULL)
                 ^
  254.           return;
  255.       bn_check_top(a);

crypto/bn/bn_lib.c:256:10: 
  254.           return;
  255.       bn_check_top(a);
  256. >     if (!BN_get_flags(a, BN_FLG_STATIC_DATA))
  257.           bn_free_d(a);
  258.       if (a->flags & BN_FLG_MALLOCED)

crypto/bn/bn_lib.c:964:1: start of procedure BN_get_flags()
    962.   }
    963.   
    964. > int BN_get_flags(const BIGNUM *b, int n)
    965.   {
    966.       return b->flags & n;

crypto/bn/bn_lib.c:966:5: 
    964.   int BN_get_flags(const BIGNUM *b, int n)
    965.   {
    966. >     return b->flags & n;
    967.   }
    968.   

crypto/bn/bn_lib.c:967:1: return from a call to BN_get_flags
    965.   {
    966.       return b->flags & n;
    967. > }
    968.   
    969.   /* Populate a BN_GENCB structure with an "old"-style callback */

crypto/bn/bn_lib.c:256:10: Taking false branch
  254.           return;
  255.       bn_check_top(a);
  256.       if (!BN_get_flags(a, BN_FLG_STATIC_DATA))
                  ^
  257.           bn_free_d(a);
  258.       if (a->flags & BN_FLG_MALLOCED)

crypto/bn/bn_lib.c:258:9: Taking false branch
  256.       if (!BN_get_flags(a, BN_FLG_STATIC_DATA))
  257.           bn_free_d(a);
  258.       if (a->flags & BN_FLG_MALLOCED)
                 ^
  259.           OPENSSL_free(a);
  260.       else {

crypto/bn/bn_lib.c:262:9: 
  260.       else {
  261.   #if OPENSSL_API_COMPAT < 0x00908000L
  262. >         a->flags |= BN_FLG_FREE;
  263.   #endif
  264.           a->d = NULL;

crypto/bn/bn_lib.c:264:9: 
  262.           a->flags |= BN_FLG_FREE;
  263.   #endif
  264. >         a->d = NULL;
  265.       }
  266.   }

crypto/bn/bn_lib.c:258:5: 
  256.       if (!BN_get_flags(a, BN_FLG_STATIC_DATA))
  257.           bn_free_d(a);
  258. >     if (a->flags & BN_FLG_MALLOCED)
  259.           OPENSSL_free(a);
  260.       else {

crypto/bn/bn_lib.c:266:1: return from a call to BN_free
  264.           a->d = NULL;
  265.       }
  266. > }
  267.   
  268.   void bn_init(BIGNUM *a)

int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
{
    int ok = 0;
    BIGNUM *q = NULL;
    *ret = 0;
    q = BN_new();
    if (q == NULL)
        goto err;
    BN_set_word(q, 1);
    if (BN_cmp(pub_key, q) <= 0)
        *ret |= DH_CHECK_PUBKEY_TOO_SMALL;
    BN_copy(q, dh->p);
    BN_sub_word(q, 1);
    if (BN_cmp(pub_key, q) >= 0)
        *ret |= DH_CHECK_PUBKEY_TOO_LARGE;
    ok = 1;
 err:
    BN_free(q);
    return (ok);
}
['int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)\n{\n    int ok = 0;\n    BIGNUM *q = NULL;\n    *ret = 0;\n    q = BN_new();\n    if (q == NULL)\n        goto err;\n    BN_set_word(q, 1);\n    if (BN_cmp(pub_key, q) <= 0)\n        *ret |= DH_CHECK_PUBKEY_TOO_SMALL;\n    BN_copy(q, dh->p);\n    BN_sub_word(q, 1);\n    if (BN_cmp(pub_key, q) >= 0)\n        *ret |= DH_CHECK_PUBKEY_TOO_LARGE;\n    ok = 1;\n err:\n    BN_free(q);\n    return (ok);\n}', 'BIGNUM *BN_new(void)\n{\n    BIGNUM *ret;\n    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n        BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    ret->flags = BN_FLG_MALLOCED;\n    bn_check_top(ret);\n    return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\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}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n    bn_check_top(a);\n    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n        return (0);\n    a->neg = 0;\n    a->d[0] = w;\n    a->top = (w ? 1 : 0);\n    bn_check_top(a);\n    return (1);\n}', 'void BN_free(BIGNUM *a)\n{\n    if (a == NULL)\n        return;\n    bn_check_top(a);\n    if (!BN_get_flags(a, BN_FLG_STATIC_DATA))\n        bn_free_d(a);\n    if (a->flags & BN_FLG_MALLOCED)\n        OPENSSL_free(a);\n    else {\n#if OPENSSL_API_COMPAT < 0x00908000L\n        a->flags |= BN_FLG_FREE;\n#endif\n        a->d = NULL;\n    }\n}', 'int BN_get_flags(const BIGNUM *b, int n)\n{\n    return b->flags & n;\n}']