apps/apps.c:1570: error: MEMORY_LEAK
  memory dynamically allocated by call to `BN_new()` at line 1555, column 16 is not reachable after line 1570, column 9.
Showing all 71 steps of the trace


apps/apps.c:1547:1: start of procedure rand_serial()
1545.   }
1546.   
1547. > int rand_serial(BIGNUM *b, ASN1_INTEGER *ai)
1548.   {
1549.       BIGNUM *btmp;

apps/apps.c:1550:5: 
1548.   {
1549.       BIGNUM *btmp;
1550. >     int ret = 0;
1551.   
1552.       if (b)

apps/apps.c:1552:9: Taking false branch
1550.       int ret = 0;
1551.   
1552.       if (b)
                ^
1553.           btmp = b;
1554.       else

apps/apps.c:1555:9: 
1553.           btmp = b;
1554.       else
1555. >         btmp = BN_new();
1556.   
1557.       if (btmp == NULL)

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)

apps/apps.c:1557:9: Taking false branch
1555.           btmp = BN_new();
1556.   
1557.       if (btmp == NULL)
                ^
1558.           return 0;
1559.   

apps/apps.c:1560:10: 
1558.           return 0;
1559.   
1560. >     if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0))
1561.           goto error;
1562.       if (ai && !BN_to_ASN1_INTEGER(btmp, ai))

crypto/bn/bn_rand.c:204:1: start of procedure BN_pseudo_rand()
  202.   }
  203.   
  204. > int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
  205.   {
  206.       return bnrand(1, rnd, bits, top, bottom);

crypto/bn/bn_rand.c:206:5: 
  204.   int BN_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)
  205.   {
  206. >     return bnrand(1, rnd, bits, top, bottom);
  207.   }
  208.   

crypto/bn/bn_rand.c:118:1: start of procedure bnrand()
    116.   #include <openssl/sha.h>
    117.   
    118. > static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
    119.   {
    120.       unsigned char *buf = NULL;

crypto/bn/bn_rand.c:120:5: 
    118.   static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
    119.   {
    120. >     unsigned char *buf = NULL;
    121.       int ret = 0, bit, bytes, mask;
    122.       time_t tim;

crypto/bn/bn_rand.c:121:5: 
    119.   {
    120.       unsigned char *buf = NULL;
    121. >     int ret = 0, bit, bytes, mask;
    122.       time_t tim;
    123.   

crypto/bn/bn_rand.c:124:9: Taking false branch
    122.       time_t tim;
    123.   
    124.       if (bits < 0 || (bits == 1 && top > 0)) {
                   ^
    125.           BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);
    126.           return 0;

crypto/bn/bn_rand.c:124:22: Taking false branch
    122.       time_t tim;
    123.   
    124.       if (bits < 0 || (bits == 1 && top > 0)) {
                                ^
    125.           BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);
    126.           return 0;

crypto/bn/bn_rand.c:129:9: Taking false branch
    127.       }
    128.   
    129.       if (bits == 0) {
                   ^
    130.           BN_zero(rnd);
    131.           return 1;

crypto/bn/bn_rand.c:134:5: 
    132.       }
    133.   
    134. >     bytes = (bits + 7) / 8;
    135.       bit = (bits - 1) % 8;
    136.       mask = 0xff << (bit + 1);

crypto/bn/bn_rand.c:135:5: 
    133.   
    134.       bytes = (bits + 7) / 8;
    135. >     bit = (bits - 1) % 8;
    136.       mask = 0xff << (bit + 1);
    137.   

crypto/bn/bn_rand.c:136:5: 
    134.       bytes = (bits + 7) / 8;
    135.       bit = (bits - 1) % 8;
    136. >     mask = 0xff << (bit + 1);
    137.   
    138.       buf = OPENSSL_malloc(bytes);

crypto/bn/bn_rand.c:138:5: 
    136.       mask = 0xff << (bit + 1);
    137.   
    138. >     buf = OPENSSL_malloc(bytes);
    139.       if (buf == NULL) {
    140.           BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);

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 true branch
      121.       void *ret = NULL;
      122.   
      123.       if (num <= 0)
                     ^
      124.           return NULL;
      125.   

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

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/bn/bn_rand.c:139:9: Taking true branch
    137.   
    138.       buf = OPENSSL_malloc(bytes);
    139.       if (buf == NULL) {
                   ^
    140.           BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);
    141.           goto err;

crypto/bn/bn_rand.c:140:9: Skipping ERR_put_error(): empty list of specs
    138.       buf = OPENSSL_malloc(bytes);
    139.       if (buf == NULL) {
    140.           BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);
                   ^
    141.           goto err;
    142.       }

crypto/bn/bn_rand.c:193:2: 
    191.           goto err;
    192.       ret = 1;
    193. >  err:
    194.       OPENSSL_clear_free(buf, bytes);
    195.       bn_check_top(rnd);

crypto/bn/bn_rand.c:194:5: 
    192.       ret = 1;
    193.    err:
    194. >     OPENSSL_clear_free(buf, bytes);
    195.       bn_check_top(rnd);
    196.       return (ret);

crypto/mem.c:248:1: start of procedure CRYPTO_clear_free()
      246.   }
      247.   
      248. > void CRYPTO_clear_free(void *str, size_t num)
      249.   {
      250.       if (str == NULL)

crypto/mem.c:250:9: Taking true branch
      248.   void CRYPTO_clear_free(void *str, size_t num)
      249.   {
      250.       if (str == NULL)
                     ^
      251.           return;
      252.       if (num)

crypto/mem.c:251:9: 
      249.   {
      250.       if (str == NULL)
      251. >         return;
      252.       if (num)
      253.           OPENSSL_cleanse(str, num);

crypto/mem.c:255:1: return from a call to CRYPTO_clear_free
      253.           OPENSSL_cleanse(str, num);
      254.       CRYPTO_free(str);
      255. > }

crypto/bn/bn_rand.c:196:5: 
    194.       OPENSSL_clear_free(buf, bytes);
    195.       bn_check_top(rnd);
    196. >     return (ret);
    197.   }
    198.   

crypto/bn/bn_rand.c:197:1: return from a call to bnrand
    195.       bn_check_top(rnd);
    196.       return (ret);
    197. > }
    198.   
    199.   int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)

crypto/bn/bn_rand.c:207:1: return from a call to BN_pseudo_rand
  205.   {
  206.       return bnrand(1, rnd, bits, top, bottom);
  207. > }
  208.   
  209.   int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)

apps/apps.c:1560:10: Taking true branch
1558.           return 0;
1559.   
1560.       if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0))
                 ^
1561.           goto error;
1562.       if (ai && !BN_to_ASN1_INTEGER(btmp, ai))

apps/apps.c:1567:2: 
1565.       ret = 1;
1566.   
1567. >  error:
1568.   
1569.       if (btmp != b)

apps/apps.c:1569:9: Taking true branch
1567.    error:
1568.   
1569.       if (btmp != b)
                ^
1570.           BN_free(btmp);
1571.   

apps/apps.c:1570:9: 
1568.   
1569.       if (btmp != b)
1570. >         BN_free(btmp);
1571.   
1572.       return ret;

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:1041:1: start of procedure BN_get_flags()
    1039.   }
    1040.   
    1041. > int BN_get_flags(const BIGNUM *b, int n)
    1042.   {
    1043.       return b->flags & n;

crypto/bn/bn_lib.c:1043:5: 
    1041.   int BN_get_flags(const BIGNUM *b, int n)
    1042.   {
    1043. >     return b->flags & n;
    1044.   }
    1045.   

crypto/bn/bn_lib.c:1044:1: return from a call to BN_get_flags
    1042.   {
    1043.       return b->flags & n;
    1044. > }
    1045.   
    1046.   /* 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 rand_serial(BIGNUM *b, ASN1_INTEGER *ai)
{
    BIGNUM *btmp;
    int ret = 0;
    if (b)
        btmp = b;
    else
        btmp = BN_new();
    if (btmp == NULL)
        return 0;
    if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0))
        goto error;
    if (ai && !BN_to_ASN1_INTEGER(btmp, ai))
        goto error;
    ret = 1;
 error:
    if (btmp != b)
        BN_free(btmp);
    return ret;
}
['int rand_serial(BIGNUM *b, ASN1_INTEGER *ai)\n{\n    BIGNUM *btmp;\n    int ret = 0;\n    if (b)\n        btmp = b;\n    else\n        btmp = BN_new();\n    if (btmp == NULL)\n        return 0;\n    if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0))\n        goto error;\n    if (ai && !BN_to_ASN1_INTEGER(btmp, ai))\n        goto error;\n    ret = 1;\n error:\n    if (btmp != b)\n        BN_free(btmp);\n    return ret;\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_pseudo_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n    return bnrand(1, rnd, bits, top, bottom);\n}', 'static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)\n{\n    unsigned char *buf = NULL;\n    int ret = 0, bit, bytes, mask;\n    time_t tim;\n    if (bits < 0 || (bits == 1 && top > 0)) {\n        BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n        return 0;\n    }\n    if (bits == 0) {\n        BN_zero(rnd);\n        return 1;\n    }\n    bytes = (bits + 7) / 8;\n    bit = (bits - 1) % 8;\n    mask = 0xff << (bit + 1);\n    buf = OPENSSL_malloc(bytes);\n    if (buf == NULL) {\n        BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    time(&tim);\n    RAND_add(&tim, sizeof(tim), 0.0);\n    if (pseudorand) {\n        if (RAND_bytes(buf, bytes) <= 0)\n            goto err;\n    } else {\n        if (RAND_bytes(buf, bytes) <= 0)\n            goto err;\n    }\n    if (pseudorand == 2) {\n        int i;\n        unsigned char c;\n        for (i = 0; i < bytes; i++) {\n            if (RAND_bytes(&c, 1) <= 0)\n                goto err;\n            if (c >= 128 && i > 0)\n                buf[i] = buf[i - 1];\n            else if (c < 42)\n                buf[i] = 0;\n            else if (c < 84)\n                buf[i] = 255;\n        }\n    }\n    if (top >= 0) {\n        if (top) {\n            if (bit == 0) {\n                buf[0] = 1;\n                buf[1] |= 0x80;\n            } else {\n                buf[0] |= (3 << (bit - 1));\n            }\n        } else {\n            buf[0] |= (1 << bit);\n        }\n    }\n    buf[0] &= ~mask;\n    if (bottom)\n        buf[bytes - 1] |= 1;\n    if (!BN_bin2bn(buf, bytes, rnd))\n        goto err;\n    ret = 1;\n err:\n    OPENSSL_clear_free(buf, bytes);\n    bn_check_top(rnd);\n    return (ret);\n}', 'void CRYPTO_clear_free(void *str, size_t num)\n{\n    if (str == NULL)\n        return;\n    if (num)\n        OPENSSL_cleanse(str, num);\n    CRYPTO_free(str);\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}']