crypto/dsa/dsa_gen.c:278: error: MEMORY_LEAK
  memory dynamically allocated to `mont` by call to `BN_MONT_CTX_new()` at line 265, column 12 is not reachable after line 278, column 7.
Showing all 55 steps of the trace


crypto/dsa/dsa_gen.c:253:1: start of procedure DSA_is_prime()
251.   	}
252.   
253. > int DSA_is_prime(BIGNUM *w, void (*callback)(), char *cb_arg)
254.   	{
255.   	int ok= -1,j,i,n;

crypto/dsa/dsa_gen.c:255:2: 
253.   int DSA_is_prime(BIGNUM *w, void (*callback)(), char *cb_arg)
254.   	{
255. > 	int ok= -1,j,i,n;
256.   	BN_CTX *ctx=NULL,*ctx2=NULL;
257.   	BIGNUM *w_1,*b,*m,*z,*tmp,*mont_1;

crypto/dsa/dsa_gen.c:256:2: 
254.   	{
255.   	int ok= -1,j,i,n;
256. > 	BN_CTX *ctx=NULL,*ctx2=NULL;
257.   	BIGNUM *w_1,*b,*m,*z,*tmp,*mont_1;
258.   	int a;

crypto/dsa/dsa_gen.c:259:2: 
257.   	BIGNUM *w_1,*b,*m,*z,*tmp,*mont_1;
258.   	int a;
259. > 	BN_MONT_CTX *mont=NULL;
260.   
261.   	if (!BN_is_bit_set(w,0)) return(0);

crypto/dsa/dsa_gen.c:261:7: 
259.   	BN_MONT_CTX *mont=NULL;
260.   
261. > 	if (!BN_is_bit_set(w,0)) return(0);
262.   
263.   	if ((ctx=BN_CTX_new()) == NULL) goto err;

crypto/bn/bn_lib.c:719:1: start of procedure BN_is_bit_set()
  717.   	}
  718.   
  719. > int BN_is_bit_set(BIGNUM *a, int n)
  720.   	{
  721.   	int i,j;

crypto/bn/bn_lib.c:723:6: Taking false branch
  721.   	int i,j;
  722.   
  723.   	if (n < 0) return(0);
              ^
  724.   	i=n/BN_BITS2;
  725.   	j=n%BN_BITS2;

crypto/bn/bn_lib.c:724:2: 
  722.   
  723.   	if (n < 0) return(0);
  724. > 	i=n/BN_BITS2;
  725.   	j=n%BN_BITS2;
  726.   	if (a->top <= i) return(0);

crypto/bn/bn_lib.c:725:2: 
  723.   	if (n < 0) return(0);
  724.   	i=n/BN_BITS2;
  725. > 	j=n%BN_BITS2;
  726.   	if (a->top <= i) return(0);
  727.   	return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);

crypto/bn/bn_lib.c:726:6: Taking false branch
  724.   	i=n/BN_BITS2;
  725.   	j=n%BN_BITS2;
  726.   	if (a->top <= i) return(0);
              ^
  727.   	return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);
  728.   	}

crypto/bn/bn_lib.c:727:10: Condition is true
  725.   	j=n%BN_BITS2;
  726.   	if (a->top <= i) return(0);
  727.   	return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);
                  ^
  728.   	}
  729.   

crypto/bn/bn_lib.c:727:9: 
  725.   	j=n%BN_BITS2;
  726.   	if (a->top <= i) return(0);
  727. > 	return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);
  728.   	}
  729.   

crypto/bn/bn_lib.c:727:2: 
  725.   	j=n%BN_BITS2;
  726.   	if (a->top <= i) return(0);
  727. > 	return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);
  728.   	}
  729.   

crypto/bn/bn_lib.c:728:2: return from a call to BN_is_bit_set
  726.   	if (a->top <= i) return(0);
  727.   	return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);
  728.   	}
          ^
  729.   
  730.   int BN_mask_bits(BIGNUM *a, int n)

crypto/dsa/dsa_gen.c:261:7: Taking false branch
259.   	BN_MONT_CTX *mont=NULL;
260.   
261.   	if (!BN_is_bit_set(w,0)) return(0);
             ^
262.   
263.   	if ((ctx=BN_CTX_new()) == NULL) goto err;

crypto/dsa/dsa_gen.c:263:6: 
261.   	if (!BN_is_bit_set(w,0)) return(0);
262.   
263. > 	if ((ctx=BN_CTX_new()) == NULL) goto err;
264.   	if ((ctx2=BN_CTX_new()) == NULL) goto err;
265.   	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;

crypto/bn/bn_lib.c:308:1: start of procedure BN_CTX_new()
  306.   
  307.   
  308. > BN_CTX *BN_CTX_new(void)
  309.   	{
  310.   	BN_CTX *ret;

crypto/bn/bn_lib.c:312:2: 
  310.   	BN_CTX *ret;
  311.   
  312. > 	ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
  313.   	if (ret == NULL)
  314.   		{

crypto/bn/bn_lib.c:313:6: Taking false branch
  311.   
  312.   	ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
  313.   	if (ret == NULL)
              ^
  314.   		{
  315.   		BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);

crypto/bn/bn_lib.c:319:2: Skipping BN_CTX_init(): empty list of specs
  317.   		}
  318.   
  319.   	BN_CTX_init(ret);
          ^
  320.   	ret->flags=BN_FLG_MALLOCED;
  321.   	return(ret);

crypto/bn/bn_lib.c:320:2: 
  318.   
  319.   	BN_CTX_init(ret);
  320. > 	ret->flags=BN_FLG_MALLOCED;
  321.   	return(ret);
  322.   	}

crypto/bn/bn_lib.c:321:2: 
  319.   	BN_CTX_init(ret);
  320.   	ret->flags=BN_FLG_MALLOCED;
  321. > 	return(ret);
  322.   	}
  323.   

crypto/bn/bn_lib.c:322:2: return from a call to BN_CTX_new
  320.   	ret->flags=BN_FLG_MALLOCED;
  321.   	return(ret);
  322.   	}
          ^
  323.   
  324.   void BN_CTX_init(BN_CTX *ctx)

crypto/dsa/dsa_gen.c:263:6: Taking false branch
261.   	if (!BN_is_bit_set(w,0)) return(0);
262.   
263.   	if ((ctx=BN_CTX_new()) == NULL) goto err;
            ^
264.   	if ((ctx2=BN_CTX_new()) == NULL) goto err;
265.   	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;

crypto/dsa/dsa_gen.c:264:6: 
262.   
263.   	if ((ctx=BN_CTX_new()) == NULL) goto err;
264. > 	if ((ctx2=BN_CTX_new()) == NULL) goto err;
265.   	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
266.   

crypto/bn/bn_lib.c:308:1: start of procedure BN_CTX_new()
  306.   
  307.   
  308. > BN_CTX *BN_CTX_new(void)
  309.   	{
  310.   	BN_CTX *ret;

crypto/bn/bn_lib.c:312:2: 
  310.   	BN_CTX *ret;
  311.   
  312. > 	ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
  313.   	if (ret == NULL)
  314.   		{

crypto/bn/bn_lib.c:313:6: Taking false branch
  311.   
  312.   	ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
  313.   	if (ret == NULL)
              ^
  314.   		{
  315.   		BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);

crypto/bn/bn_lib.c:319:2: Skipping BN_CTX_init(): empty list of specs
  317.   		}
  318.   
  319.   	BN_CTX_init(ret);
          ^
  320.   	ret->flags=BN_FLG_MALLOCED;
  321.   	return(ret);

crypto/bn/bn_lib.c:320:2: 
  318.   
  319.   	BN_CTX_init(ret);
  320. > 	ret->flags=BN_FLG_MALLOCED;
  321.   	return(ret);
  322.   	}

crypto/bn/bn_lib.c:321:2: 
  319.   	BN_CTX_init(ret);
  320.   	ret->flags=BN_FLG_MALLOCED;
  321. > 	return(ret);
  322.   	}
  323.   

crypto/bn/bn_lib.c:322:2: return from a call to BN_CTX_new
  320.   	ret->flags=BN_FLG_MALLOCED;
  321.   	return(ret);
  322.   	}
          ^
  323.   
  324.   void BN_CTX_init(BN_CTX *ctx)

crypto/dsa/dsa_gen.c:264:6: Taking false branch
262.   
263.   	if ((ctx=BN_CTX_new()) == NULL) goto err;
264.   	if ((ctx2=BN_CTX_new()) == NULL) goto err;
            ^
265.   	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
266.   

crypto/dsa/dsa_gen.c:265:6: 
263.   	if ((ctx=BN_CTX_new()) == NULL) goto err;
264.   	if ((ctx2=BN_CTX_new()) == NULL) goto err;
265. > 	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
266.   
267.   	m=   &(ctx2->bn[2]);

crypto/bn/bn_mont.c:267:1: start of procedure BN_MONT_CTX_new()
  265.   	}
  266.   
  267. > BN_MONT_CTX *BN_MONT_CTX_new(void)
  268.   	{
  269.   	BN_MONT_CTX *ret;

crypto/bn/bn_mont.c:271:6: Taking false branch
  269.   	BN_MONT_CTX *ret;
  270.   
  271.   	if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)
              ^
  272.   		return(NULL);
  273.   

crypto/bn/bn_mont.c:274:2: Skipping BN_MONT_CTX_init(): empty list of specs
  272.   		return(NULL);
  273.   
  274.   	BN_MONT_CTX_init(ret);
          ^
  275.   	ret->flags=BN_FLG_MALLOCED;
  276.   	return(ret);

crypto/bn/bn_mont.c:275:2: 
  273.   
  274.   	BN_MONT_CTX_init(ret);
  275. > 	ret->flags=BN_FLG_MALLOCED;
  276.   	return(ret);
  277.   	}

crypto/bn/bn_mont.c:276:2: 
  274.   	BN_MONT_CTX_init(ret);
  275.   	ret->flags=BN_FLG_MALLOCED;
  276. > 	return(ret);
  277.   	}
  278.   

crypto/bn/bn_mont.c:277:2: return from a call to BN_MONT_CTX_new
  275.   	ret->flags=BN_FLG_MALLOCED;
  276.   	return(ret);
  277.   	}
          ^
  278.   
  279.   void BN_MONT_CTX_init(BN_MONT_CTX *ctx)

crypto/dsa/dsa_gen.c:265:6: Taking false branch
263.   	if ((ctx=BN_CTX_new()) == NULL) goto err;
264.   	if ((ctx2=BN_CTX_new()) == NULL) goto err;
265.   	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
            ^
266.   
267.   	m=   &(ctx2->bn[2]);

crypto/dsa/dsa_gen.c:267:2: 
265.   	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
266.   
267. > 	m=   &(ctx2->bn[2]);
268.   	b=   &(ctx2->bn[3]);
269.   	z=   &(ctx2->bn[4]);

crypto/dsa/dsa_gen.c:268:2: 
266.   
267.   	m=   &(ctx2->bn[2]);
268. > 	b=   &(ctx2->bn[3]);
269.   	z=   &(ctx2->bn[4]);
270.   	w_1= &(ctx2->bn[5]);

crypto/dsa/dsa_gen.c:269:2: 
267.   	m=   &(ctx2->bn[2]);
268.   	b=   &(ctx2->bn[3]);
269. > 	z=   &(ctx2->bn[4]);
270.   	w_1= &(ctx2->bn[5]);
271.   	tmp= &(ctx2->bn[6]);

crypto/dsa/dsa_gen.c:270:2: 
268.   	b=   &(ctx2->bn[3]);
269.   	z=   &(ctx2->bn[4]);
270. > 	w_1= &(ctx2->bn[5]);
271.   	tmp= &(ctx2->bn[6]);
272.   	mont_1= &(ctx2->bn[7]);

crypto/dsa/dsa_gen.c:271:2: 
269.   	z=   &(ctx2->bn[4]);
270.   	w_1= &(ctx2->bn[5]);
271. > 	tmp= &(ctx2->bn[6]);
272.   	mont_1= &(ctx2->bn[7]);
273.   

crypto/dsa/dsa_gen.c:272:2: 
270.   	w_1= &(ctx2->bn[5]);
271.   	tmp= &(ctx2->bn[6]);
272. > 	mont_1= &(ctx2->bn[7]);
273.   
274.   	/* step 1 */

crypto/dsa/dsa_gen.c:275:2: 
273.   
274.   	/* step 1 */
275. > 	n=50;
276.   
277.   	/* step 2 */

crypto/dsa/dsa_gen.c:278:7: 
276.   
277.   	/* step 2 */
278. > 	if (!BN_sub(w_1,w,BN_value_one())) goto err;
279.   	for (a=1; !BN_is_bit_set(w_1,a); a++)
280.   		;

crypto/bn/bn_lib.c:124:1: start of procedure BN_value_one()
  122.   	}
  123.   
  124. > BIGNUM *BN_value_one(void)
  125.   	{
  126.   	static BN_ULONG data_one=1L;

crypto/bn/bn_lib.c:126:2: 
  124.   BIGNUM *BN_value_one(void)
  125.   	{
  126. > 	static BN_ULONG data_one=1L;
  127.   	static BIGNUM const_one={&data_one,1,1,0};
  128.   

crypto/bn/bn_lib.c:127:2: 
  125.   	{
  126.   	static BN_ULONG data_one=1L;
  127. > 	static BIGNUM const_one={&data_one,1,1,0};
  128.   
  129.   	return(&const_one);

crypto/bn/bn_lib.c:129:2: 
  127.   	static BIGNUM const_one={&data_one,1,1,0};
  128.   
  129. > 	return(&const_one);
  130.   	}
  131.   

crypto/bn/bn_lib.c:130:2: return from a call to BN_value_one
  128.   
  129.   	return(&const_one);
  130.   	}
          ^
  131.   
  132.   char *BN_options(void)

crypto/dsa/dsa_gen.c:278:7: Taking true branch
276.   
277.   	/* step 2 */
278.   	if (!BN_sub(w_1,w,BN_value_one())) goto err;
             ^
279.   	for (a=1; !BN_is_bit_set(w_1,a); a++)
280.   		;

int DSA_is_prime(BIGNUM *w, void (*callback)(), char *cb_arg)
	{
	int ok= -1,j,i,n;
	BN_CTX *ctx=NULL,*ctx2=NULL;
	BIGNUM *w_1,*b,*m,*z,*tmp,*mont_1;
	int a;
	BN_MONT_CTX *mont=NULL;
	if (!BN_is_bit_set(w,0)) return(0);
	if ((ctx=BN_CTX_new()) == NULL) goto err;
	if ((ctx2=BN_CTX_new()) == NULL) goto err;
	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
	m=   &(ctx2->bn[2]);
	b=   &(ctx2->bn[3]);
	z=   &(ctx2->bn[4]);
	w_1= &(ctx2->bn[5]);
	tmp= &(ctx2->bn[6]);
	mont_1= &(ctx2->bn[7]);
	n=50;
	if (!BN_sub(w_1,w,BN_value_one())) goto err;
	for (a=1; !BN_is_bit_set(w_1,a); a++)
		;
	if (!BN_rshift(m,w_1,a)) goto err;
	BN_MONT_CTX_set(mont,w,ctx);
	BN_to_montgomery(mont_1,BN_value_one(),mont,ctx);
	BN_to_montgomery(w_1,w_1,mont,ctx);
	for (i=1; i < n; i++)
		{
		BN_rand(b,BN_num_bits(w)-2 ,0,0);
		j=0;
		if (!BN_mod_exp_mont(z,b,m,w,ctx,mont)) goto err;
		if (!BN_to_montgomery(z,z,mont,ctx)) goto err;
		for (;;)
			{
			if (((j == 0) && (BN_cmp(z,mont_1) == 0)) ||
				(BN_cmp(z,w_1) == 0))
				break;
			if ((j > 0) && (BN_cmp(z,mont_1) == 0))
				{
				ok=0;
				goto err;
				}
			j++;
			if (j >= a)
				{
				ok=0;
				goto err;
				}
			if (!BN_mod_mul_montgomery(z,z,z,mont,ctx)) goto err;
			if (callback != NULL) callback(1,j,cb_arg);
			}
		}
	ok=1;
err:
	if (ok == -1) DSAerr(DSA_F_DSA_IS_PRIME,ERR_R_BN_LIB);
	BN_CTX_free(ctx);
	BN_CTX_free(ctx2);
	return(ok);
	}
['int DSA_is_prime(BIGNUM *w, void (*callback)(), char *cb_arg)\n\t{\n\tint ok= -1,j,i,n;\n\tBN_CTX *ctx=NULL,*ctx2=NULL;\n\tBIGNUM *w_1,*b,*m,*z,*tmp,*mont_1;\n\tint a;\n\tBN_MONT_CTX *mont=NULL;\n\tif (!BN_is_bit_set(w,0)) return(0);\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tif ((ctx2=BN_CTX_new()) == NULL) goto err;\n\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\tm=   &(ctx2->bn[2]);\n\tb=   &(ctx2->bn[3]);\n\tz=   &(ctx2->bn[4]);\n\tw_1= &(ctx2->bn[5]);\n\ttmp= &(ctx2->bn[6]);\n\tmont_1= &(ctx2->bn[7]);\n\tn=50;\n\tif (!BN_sub(w_1,w,BN_value_one())) goto err;\n\tfor (a=1; !BN_is_bit_set(w_1,a); a++)\n\t\t;\n\tif (!BN_rshift(m,w_1,a)) goto err;\n\tBN_MONT_CTX_set(mont,w,ctx);\n\tBN_to_montgomery(mont_1,BN_value_one(),mont,ctx);\n\tBN_to_montgomery(w_1,w_1,mont,ctx);\n\tfor (i=1; i < n; i++)\n\t\t{\n\t\tBN_rand(b,BN_num_bits(w)-2 ,0,0);\n\t\tj=0;\n\t\tif (!BN_mod_exp_mont(z,b,m,w,ctx,mont)) goto err;\n\t\tif (!BN_to_montgomery(z,z,mont,ctx)) goto err;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tif (((j == 0) && (BN_cmp(z,mont_1) == 0)) ||\n\t\t\t\t(BN_cmp(z,w_1) == 0))\n\t\t\t\tbreak;\n\t\t\tif ((j > 0) && (BN_cmp(z,mont_1) == 0))\n\t\t\t\t{\n\t\t\t\tok=0;\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tj++;\n\t\t\tif (j >= a)\n\t\t\t\t{\n\t\t\t\tok=0;\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (!BN_mod_mul_montgomery(z,z,z,mont,ctx)) goto err;\n\t\t\tif (callback != NULL) callback(1,j,cb_arg);\n\t\t\t}\n\t\t}\n\tok=1;\nerr:\n\tif (ok == -1) DSAerr(DSA_F_DSA_IS_PRIME,ERR_R_BN_LIB);\n\tBN_CTX_free(ctx);\n\tBN_CTX_free(ctx2);\n\treturn(ok);\n\t}', 'int BN_is_bit_set(BIGNUM *a, int n)\n\t{\n\tint i,j;\n\tif (n < 0) return(0);\n\ti=n/BN_BITS2;\n\tj=n%BN_BITS2;\n\tif (a->top <= i) return(0);\n\treturn((a->d[i]&(((BN_ULONG)1)<<j))?1:0);\n\t}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret;\n\tret=(BN_CTX *)Malloc(sizeof(BN_CTX));\n\tif (ret == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tBN_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}', 'BN_MONT_CTX *BN_MONT_CTX_new(void)\n\t{\n\tBN_MONT_CTX *ret;\n\tif ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)\n\t\treturn(NULL);\n\tBN_MONT_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}', 'BIGNUM *BN_value_one(void)\n\t{\n\tstatic BN_ULONG data_one=1L;\n\tstatic BIGNUM const_one={&data_one,1,1,0};\n\treturn(&const_one);\n\t}']