crypto/bn/bn_prime.c:195: error: MEMORY_LEAK
  memory dynamically allocated by call to `BN_CTX_new()` at line 169, column 12 is not reachable after line 195, column 3.
Showing all 32 steps of the trace


crypto/bn/bn_prime.c:154:1: start of procedure BN_is_prime()
152.   	}
153.   
154. > int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int,int,char *),
155.   	     BN_CTX *ctx_passed, char *cb_arg)
156.   	{

crypto/bn/bn_prime.c:157:2: 
155.   	     BN_CTX *ctx_passed, char *cb_arg)
156.   	{
157. > 	int i,j,c2=0,ret= -1;
158.   	BIGNUM *check;
159.   	BN_CTX *ctx=NULL,*ctx2=NULL;

crypto/bn/bn_prime.c:159:2: 
157.   	int i,j,c2=0,ret= -1;
158.   	BIGNUM *check;
159. > 	BN_CTX *ctx=NULL,*ctx2=NULL;
160.   	BN_MONT_CTX *mont=NULL;
161.   

crypto/bn/bn_prime.c:160:2: 
158.   	BIGNUM *check;
159.   	BN_CTX *ctx=NULL,*ctx2=NULL;
160. > 	BN_MONT_CTX *mont=NULL;
161.   
162.   	if (!BN_is_odd(a))

crypto/bn/bn_prime.c:162:7: Taking false branch
160.   	BN_MONT_CTX *mont=NULL;
161.   
162.   	if (!BN_is_odd(a))
             ^
163.   		return(0);
164.   	if (ctx_passed != NULL)

crypto/bn/bn_prime.c:162:7: Taking false branch
160.   	BN_MONT_CTX *mont=NULL;
161.   
162.   	if (!BN_is_odd(a))
             ^
163.   		return(0);
164.   	if (ctx_passed != NULL)

crypto/bn/bn_prime.c:164:6: Taking true branch
162.   	if (!BN_is_odd(a))
163.   		return(0);
164.   	if (ctx_passed != NULL)
            ^
165.   		ctx=ctx_passed;
166.   	else

crypto/bn/bn_prime.c:165:3: 
163.   		return(0);
164.   	if (ctx_passed != NULL)
165. > 		ctx=ctx_passed;
166.   	else
167.   		if ((ctx=BN_CTX_new()) == NULL) goto err;

crypto/bn/bn_prime.c:169:6: 
167.   		if ((ctx=BN_CTX_new()) == NULL) goto err;
168.   
169. > 	if ((ctx2=BN_CTX_new()) == NULL) goto err;
170.   	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
171.   

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/bn/bn_prime.c:169:6: Taking false branch
167.   		if ((ctx=BN_CTX_new()) == NULL) goto err;
168.   
169.   	if ((ctx2=BN_CTX_new()) == NULL) goto err;
            ^
170.   	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
171.   

crypto/bn/bn_prime.c:170:6: 
168.   
169.   	if ((ctx2=BN_CTX_new()) == NULL) goto err;
170. > 	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
171.   
172.   	check= &(ctx->bn[ctx->tos++]);

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/bn/bn_prime.c:170:6: Taking false branch
168.   
169.   	if ((ctx2=BN_CTX_new()) == NULL) goto err;
170.   	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
            ^
171.   
172.   	check= &(ctx->bn[ctx->tos++]);

crypto/bn/bn_prime.c:172:2: 
170.   	if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
171.   
172. > 	check= &(ctx->bn[ctx->tos++]);
173.   
174.   	/* Setup the montgomery structure */

crypto/bn/bn_prime.c:175:7: Taking true branch
173.   
174.   	/* Setup the montgomery structure */
175.   	if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;
             ^
176.   
177.   	for (i=0; i<checks; i++)

crypto/bn/bn_prime.c:190:1: 
188.   		}
189.   	ret=1;
190. > err:
191.   	ctx->tos--;
192.   	if ((ctx_passed == NULL) && (ctx != NULL))

crypto/bn/bn_prime.c:191:2: 
189.   	ret=1;
190.   err:
191. > 	ctx->tos--;
192.   	if ((ctx_passed == NULL) && (ctx != NULL))
193.   		BN_CTX_free(ctx);

crypto/bn/bn_prime.c:192:7: Taking false branch
190.   err:
191.   	ctx->tos--;
192.   	if ((ctx_passed == NULL) && (ctx != NULL))
             ^
193.   		BN_CTX_free(ctx);
194.   	if (ctx2 != NULL)

crypto/bn/bn_prime.c:194:6: Taking true branch
192.   	if ((ctx_passed == NULL) && (ctx != NULL))
193.   		BN_CTX_free(ctx);
194.   	if (ctx2 != NULL)
            ^
195.   		BN_CTX_free(ctx2);
196.   	if (mont != NULL) BN_MONT_CTX_free(mont);

crypto/bn/bn_prime.c:195:3: Skipping BN_CTX_free(): empty list of specs
193.   		BN_CTX_free(ctx);
194.   	if (ctx2 != NULL)
195.   		BN_CTX_free(ctx2);
         ^
196.   	if (mont != NULL) BN_MONT_CTX_free(mont);
197.   		

int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int,int,char *),
	     BN_CTX *ctx_passed, char *cb_arg)
	{
	int i,j,c2=0,ret= -1;
	BIGNUM *check;
	BN_CTX *ctx=NULL,*ctx2=NULL;
	BN_MONT_CTX *mont=NULL;
	if (!BN_is_odd(a))
		return(0);
	if (ctx_passed != NULL)
		ctx=ctx_passed;
	else
		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;
	check= &(ctx->bn[ctx->tos++]);
	if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;
	for (i=0; i<checks; i++)
		{
		if (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;
		j=witness(check,a,ctx,ctx2,mont);
		if (j == -1) goto err;
		if (j)
			{
			ret=0;
			goto err;
			}
		if (callback != NULL) callback(1,c2++,cb_arg);
		}
	ret=1;
err:
	ctx->tos--;
	if ((ctx_passed == NULL) && (ctx != NULL))
		BN_CTX_free(ctx);
	if (ctx2 != NULL)
		BN_CTX_free(ctx2);
	if (mont != NULL) BN_MONT_CTX_free(mont);
	return(ret);
	}
['int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int,int,char *),\n\t     BN_CTX *ctx_passed, char *cb_arg)\n\t{\n\tint i,j,c2=0,ret= -1;\n\tBIGNUM *check;\n\tBN_CTX *ctx=NULL,*ctx2=NULL;\n\tBN_MONT_CTX *mont=NULL;\n\tif (!BN_is_odd(a))\n\t\treturn(0);\n\tif (ctx_passed != NULL)\n\t\tctx=ctx_passed;\n\telse\n\t\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\tcheck= &(ctx->bn[ctx->tos++]);\n\tif (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;\n\tfor (i=0; i<checks; i++)\n\t\t{\n\t\tif (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;\n\t\tj=witness(check,a,ctx,ctx2,mont);\n\t\tif (j == -1) goto err;\n\t\tif (j)\n\t\t\t{\n\t\t\tret=0;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (callback != NULL) callback(1,c2++,cb_arg);\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tif ((ctx_passed == NULL) && (ctx != NULL))\n\t\tBN_CTX_free(ctx);\n\tif (ctx2 != NULL)\n\t\tBN_CTX_free(ctx2);\n\tif (mont != NULL) BN_MONT_CTX_free(mont);\n\treturn(ret);\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}']