Fix memory leak with bcsqrt on number 0<X<1

This commit is contained in:
Nikita Popov 2020-11-12 11:37:54 +01:00
parent d033d5c07a
commit 3d2819e491
2 changed files with 3 additions and 1 deletions

View File

@ -70,7 +70,6 @@ bc_sqrt (bc_num *num, int scale)
/* Initialize the variables. */
rscale = MAX (scale, (*num)->n_scale);
bc_init_num(&guess);
bc_init_num(&guess1);
bc_init_num(&diff);
point5 = bc_new_num (1,1);
@ -87,6 +86,7 @@ bc_sqrt (bc_num *num, int scale)
else
{
/* The number is greater than 1. Guess should start at 10^(exp/2). */
bc_init_num(&guess);
bc_int2num (&guess,10);
bc_int2num (&guess1,(*num)->n_len);

View File

@ -9,8 +9,10 @@ bcmath.scale=0
echo bcsqrt("9"),"\n";
echo bcsqrt("9.444", 2),"\n";
echo bcsqrt("1928372132132819737213", 5),"\n";
echo bcsqrt("0.5", 5), "\n";
?>
--EXPECT--
3
3.07
43913234134.28826
0.70710