crypto/dsa/dsa_gen.c:657: error: MEMORY_LEAK
  memory dynamically allocated to `return` by call to `BN_CTX_new()` at line 652, column 11 is not reachable after line 657, column 9.
Showing all 76 steps of the trace


crypto/dsa/dsa_gen.c:646:1: start of procedure dsa_paramgen_check_g()
644.   }
645.   
646. > int dsa_paramgen_check_g(DSA *dsa)
647.   {
648.       BN_CTX *ctx;

crypto/dsa/dsa_gen.c:650:5: 
648.       BN_CTX *ctx;
649.       BIGNUM *tmp;
650. >     BN_MONT_CTX *mont = NULL;
651.       int rv = -1;
652.       ctx = BN_CTX_new();

crypto/dsa/dsa_gen.c:651:5: 
649.       BIGNUM *tmp;
650.       BN_MONT_CTX *mont = NULL;
651. >     int rv = -1;
652.       ctx = BN_CTX_new();
653.       if (ctx == NULL)

crypto/dsa/dsa_gen.c:652:5: 
650.       BN_MONT_CTX *mont = NULL;
651.       int rv = -1;
652. >     ctx = BN_CTX_new();
653.       if (ctx == NULL)
654.           return -1;

crypto/bn/bn_ctx.c:188:1: start of procedure BN_CTX_new()
  186.   
  187.   
  188. > BN_CTX *BN_CTX_new(void)
  189.   {
  190.       BN_CTX *ret;

crypto/bn/bn_ctx.c:192:9: 
  190.       BN_CTX *ret;
  191.   
  192. >     if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
  193.           BNerr(BN_F_BN_CTX_NEW, ERR_R_MALLOC_FAILURE);
  194.           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_ctx.c:192:9: Taking false branch
  190.       BN_CTX *ret;
  191.   
  192.       if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
                 ^
  193.           BNerr(BN_F_BN_CTX_NEW, ERR_R_MALLOC_FAILURE);
  194.           return NULL;

crypto/bn/bn_ctx.c:197:5: 
  195.       }
  196.       /* Initialise the structure */
  197. >     BN_POOL_init(&ret->pool);
  198.       BN_STACK_init(&ret->stack);
  199.       return ret;

crypto/bn/bn_ctx.c:334:1: start of procedure BN_POOL_init()
    332.   /***********/
    333.   
    334. > static void BN_POOL_init(BN_POOL *p)
    335.   {
    336.       p->head = p->current = p->tail = NULL;

crypto/bn/bn_ctx.c:336:5: 
    334.   static void BN_POOL_init(BN_POOL *p)
    335.   {
    336. >     p->head = p->current = p->tail = NULL;
    337.       p->used = p->size = 0;
    338.   }

crypto/bn/bn_ctx.c:337:5: 
    335.   {
    336.       p->head = p->current = p->tail = NULL;
    337. >     p->used = p->size = 0;
    338.   }
    339.   

crypto/bn/bn_ctx.c:338:1: return from a call to BN_POOL_init
    336.       p->head = p->current = p->tail = NULL;
    337.       p->used = p->size = 0;
    338. > }
    339.   
    340.   static void BN_POOL_finish(BN_POOL *p)

crypto/bn/bn_ctx.c:198:5: 
  196.       /* Initialise the structure */
  197.       BN_POOL_init(&ret->pool);
  198. >     BN_STACK_init(&ret->stack);
  199.       return ret;
  200.   }

crypto/bn/bn_ctx.c:293:1: start of procedure BN_STACK_init()
    291.   /************/
    292.   
    293. > static void BN_STACK_init(BN_STACK *st)
    294.   {
    295.       st->indexes = NULL;

crypto/bn/bn_ctx.c:295:5: 
    293.   static void BN_STACK_init(BN_STACK *st)
    294.   {
    295. >     st->indexes = NULL;
    296.       st->depth = st->size = 0;
    297.   }

crypto/bn/bn_ctx.c:296:5: 
    294.   {
    295.       st->indexes = NULL;
    296. >     st->depth = st->size = 0;
    297.   }
    298.   

crypto/bn/bn_ctx.c:297:1: return from a call to BN_STACK_init
    295.       st->indexes = NULL;
    296.       st->depth = st->size = 0;
    297. > }
    298.   
    299.   static void BN_STACK_finish(BN_STACK *st)

crypto/bn/bn_ctx.c:199:5: 
  197.       BN_POOL_init(&ret->pool);
  198.       BN_STACK_init(&ret->stack);
  199. >     return ret;
  200.   }
  201.   

crypto/bn/bn_ctx.c:200:1: return from a call to BN_CTX_new
  198.       BN_STACK_init(&ret->stack);
  199.       return ret;
  200. > }
  201.   
  202.   BN_CTX *BN_CTX_secure_new(void)

crypto/dsa/dsa_gen.c:653:9: Taking false branch
651.       int rv = -1;
652.       ctx = BN_CTX_new();
653.       if (ctx == NULL)
               ^
654.           return -1;
655.       BN_CTX_start(ctx);

crypto/dsa/dsa_gen.c:655:5: 
653.       if (ctx == NULL)
654.           return -1;
655. >     BN_CTX_start(ctx);
656.       if (BN_cmp(dsa->g, BN_value_one()) <= 0)
657.           return 0;

crypto/bn/bn_ctx.c:235:1: start of procedure BN_CTX_start()
  233.   }
  234.   
  235. > void BN_CTX_start(BN_CTX *ctx)
  236.   {
  237.       CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_ctx.c:239:9: Taking false branch
  237.       CTXDBG_ENTRY("BN_CTX_start", ctx);
  238.       /* If we're already overflowing ... */
  239.       if (ctx->err_stack || ctx->too_many)
                 ^
  240.           ctx->err_stack++;
  241.       /* (Try to) get a new frame pointer */

crypto/bn/bn_ctx.c:239:27: Taking false branch
  237.       CTXDBG_ENTRY("BN_CTX_start", ctx);
  238.       /* If we're already overflowing ... */
  239.       if (ctx->err_stack || ctx->too_many)
                                   ^
  240.           ctx->err_stack++;
  241.       /* (Try to) get a new frame pointer */

crypto/bn/bn_ctx.c:242:15: 
  240.           ctx->err_stack++;
  241.       /* (Try to) get a new frame pointer */
  242. >     else if (!BN_STACK_push(&ctx->stack, ctx->used)) {
  243.           BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);
  244.           ctx->err_stack++;

crypto/bn/bn_ctx.c:306:1: start of procedure BN_STACK_push()
    304.   
    305.   
    306. > static int BN_STACK_push(BN_STACK *st, unsigned int idx)
    307.   {
    308.       if (st->depth == st->size) {

crypto/bn/bn_ctx.c:308:9: Taking true branch
    306.   static int BN_STACK_push(BN_STACK *st, unsigned int idx)
    307.   {
    308.       if (st->depth == st->size) {
                   ^
    309.           /* Need to expand */
    310.           unsigned int newsize =

crypto/bn/bn_ctx.c:311:13: Condition is false
    309.           /* Need to expand */
    310.           unsigned int newsize =
    311.               st->size ? (st->size * 3 / 2) : BN_CTX_START_FRAMES;
                       ^
    312.           unsigned int *newitems = OPENSSL_malloc(sizeof(*newitems) * newsize);
    313.           if (newitems == NULL)

crypto/bn/bn_ctx.c:310:9: 
    308.       if (st->depth == st->size) {
    309.           /* Need to expand */
    310. >         unsigned int newsize =
    311.               st->size ? (st->size * 3 / 2) : BN_CTX_START_FRAMES;
    312.           unsigned int *newitems = OPENSSL_malloc(sizeof(*newitems) * newsize);

crypto/bn/bn_ctx.c:312:9: 
    310.           unsigned int newsize =
    311.               st->size ? (st->size * 3 / 2) : BN_CTX_START_FRAMES;
    312. >         unsigned int *newitems = OPENSSL_malloc(sizeof(*newitems) * newsize);
    313.           if (newitems == NULL)
    314.               return 0;

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/bn/bn_ctx.c:313:13: Taking false branch
    311.               st->size ? (st->size * 3 / 2) : BN_CTX_START_FRAMES;
    312.           unsigned int *newitems = OPENSSL_malloc(sizeof(*newitems) * newsize);
    313.           if (newitems == NULL)
                       ^
    314.               return 0;
    315.           if (st->depth)

crypto/bn/bn_ctx.c:315:13: Taking false branch
    313.           if (newitems == NULL)
    314.               return 0;
    315.           if (st->depth)
                       ^
    316.               memcpy(newitems, st->indexes, sizeof(*newitems) * st->depth);
    317.           OPENSSL_free(st->indexes);

crypto/bn/bn_ctx.c:317:9: 
    315.           if (st->depth)
    316.               memcpy(newitems, st->indexes, sizeof(*newitems) * st->depth);
    317. >         OPENSSL_free(st->indexes);
    318.           st->indexes = newitems;
    319.           st->size = newsize;

crypto/mem.c:233:1: start of procedure CRYPTO_free()
      231.   }
      232.   
      233. > void CRYPTO_free(void *str)
      234.   {
      235.   #ifndef OPENSSL_NO_CRYPTO_MDEBUG

crypto/mem.c:244:5: 
      242.       }
      243.   #else
      244. >     free(str);
      245.   #endif
      246.   }

crypto/mem.c:246:1: return from a call to CRYPTO_free
      244.       free(str);
      245.   #endif
      246. > }
      247.   
      248.   void CRYPTO_clear_free(void *str, size_t num)

crypto/bn/bn_ctx.c:318:9: 
    316.               memcpy(newitems, st->indexes, sizeof(*newitems) * st->depth);
    317.           OPENSSL_free(st->indexes);
    318. >         st->indexes = newitems;
    319.           st->size = newsize;
    320.       }

crypto/bn/bn_ctx.c:319:9: 
    317.           OPENSSL_free(st->indexes);
    318.           st->indexes = newitems;
    319. >         st->size = newsize;
    320.       }
    321.       st->indexes[(st->depth)++] = idx;

crypto/bn/bn_ctx.c:321:5: 
    319.           st->size = newsize;
    320.       }
    321. >     st->indexes[(st->depth)++] = idx;
    322.       return 1;
    323.   }

crypto/bn/bn_ctx.c:322:5: 
    320.       }
    321.       st->indexes[(st->depth)++] = idx;
    322. >     return 1;
    323.   }
    324.   

crypto/bn/bn_ctx.c:323:1: return from a call to BN_STACK_push
    321.       st->indexes[(st->depth)++] = idx;
    322.       return 1;
    323. > }
    324.   
    325.   static unsigned int BN_STACK_pop(BN_STACK *st)

crypto/bn/bn_ctx.c:242:15: Taking false branch
  240.           ctx->err_stack++;
  241.       /* (Try to) get a new frame pointer */
  242.       else if (!BN_STACK_push(&ctx->stack, ctx->used)) {
                       ^
  243.           BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);
  244.           ctx->err_stack++;

crypto/bn/bn_ctx.c:239:5: 
  237.       CTXDBG_ENTRY("BN_CTX_start", ctx);
  238.       /* If we're already overflowing ... */
  239. >     if (ctx->err_stack || ctx->too_many)
  240.           ctx->err_stack++;
  241.       /* (Try to) get a new frame pointer */

crypto/bn/bn_ctx.c:247:1: return from a call to BN_CTX_start
  245.       }
  246.       CTXDBG_EXIT(ctx);
  247. > }
  248.   
  249.   void BN_CTX_end(BN_CTX *ctx)

crypto/dsa/dsa_gen.c:656:9: 
654.           return -1;
655.       BN_CTX_start(ctx);
656. >     if (BN_cmp(dsa->g, BN_value_one()) <= 0)
657.           return 0;
658.       if (BN_cmp(dsa->g, dsa->p) >= 0)

crypto/bn/bn_lib.c:133:1: start of procedure BN_value_one()
  131.   #endif
  132.   
  133. > const BIGNUM *BN_value_one(void)
  134.   {
  135.       static const BN_ULONG data_one = 1L;

crypto/bn/bn_lib.c:135:5: 
  133.   const BIGNUM *BN_value_one(void)
  134.   {
  135. >     static const BN_ULONG data_one = 1L;
  136.       static const BIGNUM const_one =
  137.           { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };

crypto/bn/bn_lib.c:136:5: 
  134.   {
  135.       static const BN_ULONG data_one = 1L;
  136. >     static const BIGNUM const_one =
  137.           { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };
  138.   

crypto/bn/bn_lib.c:139:5: 
  137.           { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };
  138.   
  139. >     return (&const_one);
  140.   }
  141.   

crypto/bn/bn_lib.c:140:1: return from a call to BN_value_one
  138.   
  139.       return (&const_one);
  140. > }
  141.   
  142.   int BN_num_bits_word(BN_ULONG l)

crypto/dsa/dsa_gen.c:656:9: Taking true branch
654.           return -1;
655.       BN_CTX_start(ctx);
656.       if (BN_cmp(dsa->g, BN_value_one()) <= 0)
               ^
657.           return 0;
658.       if (BN_cmp(dsa->g, dsa->p) >= 0)

crypto/dsa/dsa_gen.c:657:9: 
655.       BN_CTX_start(ctx);
656.       if (BN_cmp(dsa->g, BN_value_one()) <= 0)
657. >         return 0;
658.       if (BN_cmp(dsa->g, dsa->p) >= 0)
659.           return 0;

int dsa_paramgen_check_g(DSA *dsa)
{
    BN_CTX *ctx;
    BIGNUM *tmp;
    BN_MONT_CTX *mont = NULL;
    int rv = -1;
    ctx = BN_CTX_new();
    if (ctx == NULL)
        return -1;
    BN_CTX_start(ctx);
    if (BN_cmp(dsa->g, BN_value_one()) <= 0)
        return 0;
    if (BN_cmp(dsa->g, dsa->p) >= 0)
        return 0;
    tmp = BN_CTX_get(ctx);
    if (!tmp)
        goto err;
    if ((mont = BN_MONT_CTX_new()) == NULL)
        goto err;
    if (!BN_MONT_CTX_set(mont, dsa->p, ctx))
        goto err;
    if (!BN_mod_exp_mont(tmp, dsa->g, dsa->q, dsa->p, ctx, mont))
        goto err;
    if (!BN_cmp(tmp, BN_value_one()))
        rv = 1;
    else
        rv = 0;
 err:
    BN_CTX_end(ctx);
    BN_MONT_CTX_free(mont);
    BN_CTX_free(ctx);
    return rv;
}
['int dsa_paramgen_check_g(DSA *dsa)\n{\n    BN_CTX *ctx;\n    BIGNUM *tmp;\n    BN_MONT_CTX *mont = NULL;\n    int rv = -1;\n    ctx = BN_CTX_new();\n    if (ctx == NULL)\n        return -1;\n    BN_CTX_start(ctx);\n    if (BN_cmp(dsa->g, BN_value_one()) <= 0)\n        return 0;\n    if (BN_cmp(dsa->g, dsa->p) >= 0)\n        return 0;\n    tmp = BN_CTX_get(ctx);\n    if (!tmp)\n        goto err;\n    if ((mont = BN_MONT_CTX_new()) == NULL)\n        goto err;\n    if (!BN_MONT_CTX_set(mont, dsa->p, ctx))\n        goto err;\n    if (!BN_mod_exp_mont(tmp, dsa->g, dsa->q, dsa->p, ctx, mont))\n        goto err;\n    if (!BN_cmp(tmp, BN_value_one()))\n        rv = 1;\n    else\n        rv = 0;\n err:\n    BN_CTX_end(ctx);\n    BN_MONT_CTX_free(mont);\n    BN_CTX_free(ctx);\n    return rv;\n}', 'BN_CTX *BN_CTX_new(void)\n{\n    BN_CTX *ret;\n    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n        BNerr(BN_F_BN_CTX_NEW, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    BN_POOL_init(&ret->pool);\n    BN_STACK_init(&ret->stack);\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}', 'static void BN_POOL_init(BN_POOL *p)\n{\n    p->head = p->current = p->tail = NULL;\n    p->used = p->size = 0;\n}', 'static void BN_STACK_init(BN_STACK *st)\n{\n    st->indexes = NULL;\n    st->depth = st->size = 0;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n    CTXDBG_ENTRY("BN_CTX_start", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        ctx->err_stack++;\n    else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n        BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        ctx->err_stack++;\n    }\n    CTXDBG_EXIT(ctx);\n}', 'static int BN_STACK_push(BN_STACK *st, unsigned int idx)\n{\n    if (st->depth == st->size) {\n        unsigned int newsize =\n            st->size ? (st->size * 3 / 2) : BN_CTX_START_FRAMES;\n        unsigned int *newitems = OPENSSL_malloc(sizeof(*newitems) * newsize);\n        if (newitems == NULL)\n            return 0;\n        if (st->depth)\n            memcpy(newitems, st->indexes, sizeof(*newitems) * st->depth);\n        OPENSSL_free(st->indexes);\n        st->indexes = newitems;\n        st->size = newsize;\n    }\n    st->indexes[(st->depth)++] = idx;\n    return 1;\n}', 'void CRYPTO_free(void *str)\n{\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_free(str, 0);\n        free(str);\n        CRYPTO_mem_debug_free(str, 1);\n    } else {\n        free(str);\n    }\n#else\n    free(str);\n#endif\n}', 'const BIGNUM *BN_value_one(void)\n{\n    static const BN_ULONG data_one = 1L;\n    static const BIGNUM const_one =\n        { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };\n    return (&const_one);\n}']