crypto/bn/bn_rand.c:105: error: MEMORY_LEAK
  memory dynamically allocated by call to `CRYPTO_malloc()` at line 41, column 11 is not reachable after line 105, column 5.
Showing all 40 steps of the trace


crypto/bn/bn_rand.c:23:1: start of procedure bnrand()
21.   } BNRAND_FLAG;
22.   
23. > static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom)
24.   {
25.       unsigned char *buf = NULL;

crypto/bn/bn_rand.c:25:5: 
23.   static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom)
24.   {
25. >     unsigned char *buf = NULL;
26.       int b, ret = 0, bit, bytes, mask;
27.   

crypto/bn/bn_rand.c:26:5: 
24.   {
25.       unsigned char *buf = NULL;
26. >     int b, ret = 0, bit, bytes, mask;
27.   
28.       if (bits == 0) {

crypto/bn/bn_rand.c:28:9: Taking false branch
26.       int b, ret = 0, bit, bytes, mask;
27.   
28.       if (bits == 0) {
              ^
29.           if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)
30.               goto toosmall;

crypto/bn/bn_rand.c:34:9: Taking false branch
32.           return 1;
33.       }
34.       if (bits < 0 || (bits == 1 && top > 0))
              ^
35.           goto toosmall;
36.   

crypto/bn/bn_rand.c:34:22: Taking false branch
32.           return 1;
33.       }
34.       if (bits < 0 || (bits == 1 && top > 0))
                           ^
35.           goto toosmall;
36.   

crypto/bn/bn_rand.c:37:5: 
35.           goto toosmall;
36.   
37. >     bytes = (bits + 7) / 8;
38.       bit = (bits - 1) % 8;
39.       mask = 0xff << (bit + 1);

crypto/bn/bn_rand.c:38:5: 
36.   
37.       bytes = (bits + 7) / 8;
38. >     bit = (bits - 1) % 8;
39.       mask = 0xff << (bit + 1);
40.   

crypto/bn/bn_rand.c:39:5: 
37.       bytes = (bits + 7) / 8;
38.       bit = (bits - 1) % 8;
39. >     mask = 0xff << (bit + 1);
40.   
41.       buf = OPENSSL_malloc(bytes);

crypto/bn/bn_rand.c:41:5: 
39.       mask = 0xff << (bit + 1);
40.   
41. >     buf = OPENSSL_malloc(bytes);
42.       if (buf == NULL) {
43.           BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);

crypto/mem.c:192:1: start of procedure CRYPTO_malloc()
  190.   #endif
  191.   
  192. > void *CRYPTO_malloc(size_t num, const char *file, int line)
  193.   {
  194.       void *ret = NULL;

crypto/mem.c:194:5: 
  192.   void *CRYPTO_malloc(size_t num, const char *file, int line)
  193.   {
  194. >     void *ret = NULL;
  195.   
  196.       INCREMENT(malloc_count);

crypto/mem.c:197:9: Taking false branch
  195.   
  196.       INCREMENT(malloc_count);
  197.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                 ^
  198.           return malloc_impl(num, file, line);
  199.   

crypto/mem.c:200:9: Taking false branch
  198.           return malloc_impl(num, file, line);
  199.   
  200.       if (num == 0)
                 ^
  201.           return NULL;
  202.   

crypto/mem.c:204:9: Taking true branch
  202.   
  203.       FAILTEST();
  204.       if (allow_customize) {
                 ^
  205.           /*
  206.            * Disallow customization after the first allocation. We only set this

crypto/mem.c:210:9: 
  208.            * allocation.
  209.            */
  210. >         allow_customize = 0;
  211.       }
  212.   #if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)

crypto/mem.c:221:5: 
  219.       }
  220.   #else
  221. >     (void)(file); (void)(line);
  222.       ret = malloc(num);
  223.   #endif

crypto/mem.c:221:19: 
  219.       }
  220.   #else
  221. >     (void)(file); (void)(line);
  222.       ret = malloc(num);
  223.   #endif

crypto/mem.c:222:5: 
  220.   #else
  221.       (void)(file); (void)(line);
  222. >     ret = malloc(num);
  223.   #endif
  224.   

crypto/mem.c:225:5: 
  223.   #endif
  224.   
  225. >     return ret;
  226.   }
  227.   

crypto/mem.c:226:1: return from a call to CRYPTO_malloc
  224.   
  225.       return ret;
  226. > }
  227.   
  228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/bn/bn_rand.c:42:9: Taking false branch
40.   
41.       buf = OPENSSL_malloc(bytes);
42.       if (buf == NULL) {
              ^
43.           BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);
44.           goto err;

crypto/bn/bn_rand.c:53:5: 
51.        */
52.   #if defined(FIPS_MODE)
53. >     BNerr(BN_F_BNRAND, ERR_R_INTERNAL_ERROR);
54.       goto err;
55.   #else

providers/fips/fipsprov.c:246:1: start of procedure ERR_put_error()
  244.   }
  245.   
  246. > void ERR_put_error(int lib, int func, int reason, const char *file, int line)
  247.   {
  248.       /*

providers/fips/fipsprov.c:254:5: Skipping __function_pointer__(): unresolved function pointer
  252.        * so we'll need to come up with something else for them.
  253.        */
  254.       c_put_error(lib, func, reason, file, line);
             ^
  255.   }
  256.   

providers/fips/fipsprov.c:255:1: return from a call to ERR_put_error
  253.        */
  254.       c_put_error(lib, func, reason, file, line);
  255. > }
  256.   
  257.   void ERR_add_error_data(int num, ...)

crypto/bn/bn_rand.c:104:2: 
102.           goto err;
103.       ret = 1;
104. >  err:
105.       OPENSSL_clear_free(buf, bytes);
106.       bn_check_top(rnd);

crypto/bn/bn_rand.c:105:5: 
103.       ret = 1;
104.    err:
105. >     OPENSSL_clear_free(buf, bytes);
106.       bn_check_top(rnd);
107.       return ret;

crypto/mem.c:316:1: start of procedure CRYPTO_clear_free()
  314.   }
  315.   
  316. > void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  317.   {
  318.       if (str == NULL)

crypto/mem.c:318:9: Taking false branch
  316.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)
  317.   {
  318.       if (str == NULL)
                 ^
  319.           return;
  320.       if (num)

crypto/mem.c:320:9: Taking true branch
  318.       if (str == NULL)
  319.           return;
  320.       if (num)
                 ^
  321.           OPENSSL_cleanse(str, num);
  322.       CRYPTO_free(str, file, line);

crypto/mem.c:321:9: Skipping OPENSSL_cleanse(): method has no implementation
  319.           return;
  320.       if (num)
  321.           OPENSSL_cleanse(str, num);
                 ^
  322.       CRYPTO_free(str, file, line);
  323.   }

crypto/mem.c:322:5: 
  320.       if (num)
  321.           OPENSSL_cleanse(str, num);
  322. >     CRYPTO_free(str, file, line);
  323.   }

crypto/mem.c:295:1: start of procedure CRYPTO_free()
    293.   }
    294.   
    295. > void CRYPTO_free(void *str, const char *file, int line)
    296.   {
    297.       INCREMENT(free_count);

crypto/mem.c:298:9: Taking true branch
    296.   {
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                   ^
    299.           free_impl(str, file, line);
    300.           return;

crypto/mem.c:298:30: Taking true branch
    296.   {
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
                                        ^
    299.           free_impl(str, file, line);
    300.           return;

crypto/mem.c:299:9: Skipping __function_pointer__(): unresolved function pointer
    297.       INCREMENT(free_count);
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    299.           free_impl(str, file, line);
                   ^
    300.           return;
    301.       }

crypto/mem.c:300:9: 
    298.       if (free_impl != NULL && free_impl != &CRYPTO_free) {
    299.           free_impl(str, file, line);
    300. >         return;
    301.       }
    302.   

crypto/mem.c:314:1: return from a call to CRYPTO_free
    312.       free(str);
    313.   #endif
    314. > }
    315.   
    316.   void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)

crypto/mem.c:323:1: return from a call to CRYPTO_clear_free
  321.           OPENSSL_cleanse(str, num);
  322.       CRYPTO_free(str, file, line);
  323. > }

static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom)
{
    unsigned char *buf = NULL;
    int b, ret = 0, bit, bytes, mask;
    if (bits == 0) {
        if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)
            goto toosmall;
        BN_zero(rnd);
        return 1;
    }
    if (bits < 0 || (bits == 1 && top > 0))
        goto toosmall;
    bytes = (bits + 7) / 8;
    bit = (bits - 1) % 8;
    mask = 0xff << (bit + 1);
    buf = OPENSSL_malloc(bytes);
    if (buf == NULL) {
        BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);
        goto err;
    }
#if defined(FIPS_MODE)
    BNerr(BN_F_BNRAND, ERR_R_INTERNAL_ERROR);
    goto err;
#else
    b = flag == NORMAL ? RAND_bytes(buf, bytes) : RAND_priv_bytes(buf, bytes);
#endif
    if (b <= 0)
        goto err;
    if (flag == TESTING) {
        int i;
        unsigned char c;
        for (i = 0; i < bytes; i++) {
#if !defined(FIPS_MODE)
            if (RAND_bytes(&c, 1) <= 0)
                goto err;
#endif
            if (c >= 128 && i > 0)
                buf[i] = buf[i - 1];
            else if (c < 42)
                buf[i] = 0;
            else if (c < 84)
                buf[i] = 255;
        }
    }
    if (top >= 0) {
        if (top) {
            if (bit == 0) {
                buf[0] = 1;
                buf[1] |= 0x80;
            } else {
                buf[0] |= (3 << (bit - 1));
            }
        } else {
            buf[0] |= (1 << bit);
        }
    }
    buf[0] &= ~mask;
    if (bottom)
        buf[bytes - 1] |= 1;
    if (!BN_bin2bn(buf, bytes, rnd))
        goto err;
    ret = 1;
 err:
    OPENSSL_clear_free(buf, bytes);
    bn_check_top(rnd);
    return ret;
toosmall:
    BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);
    return 0;
}
['static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom)\n{\n    unsigned char *buf = NULL;\n    int b, ret = 0, bit, bytes, mask;\n    if (bits == 0) {\n        if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)\n            goto toosmall;\n        BN_zero(rnd);\n        return 1;\n    }\n    if (bits < 0 || (bits == 1 && top > 0))\n        goto toosmall;\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#if defined(FIPS_MODE)\n    BNerr(BN_F_BNRAND, ERR_R_INTERNAL_ERROR);\n    goto err;\n#else\n    b = flag == NORMAL ? RAND_bytes(buf, bytes) : RAND_priv_bytes(buf, bytes);\n#endif\n    if (b <= 0)\n        goto err;\n    if (flag == TESTING) {\n        int i;\n        unsigned char c;\n        for (i = 0; i < bytes; i++) {\n#if !defined(FIPS_MODE)\n            if (RAND_bytes(&c, 1) <= 0)\n                goto err;\n#endif\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;\ntoosmall:\n    BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n    return 0;\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    if (allow_customize) {\n        allow_customize = 0;\n    }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\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}', 'void ERR_put_error(int lib, int func, int reason, const char *file, int line)\n{\n    c_put_error(lib, func, reason, file, line);\n}', 'void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)\n{\n    if (str == NULL)\n        return;\n    if (num)\n        OPENSSL_cleanse(str, num);\n    CRYPTO_free(str, file, line);\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#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\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}']