Skip to content

Commit 3d2819e

Browse files
committed
Fix memory leak with bcsqrt on number 0<X<1
1 parent d033d5c commit 3d2819e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

ext/bcmath/libbcmath/src/sqrt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ bc_sqrt (bc_num *num, int scale)
7070

7171
/* Initialize the variables. */
7272
rscale = MAX (scale, (*num)->n_scale);
73-
bc_init_num(&guess);
7473
bc_init_num(&guess1);
7574
bc_init_num(&diff);
7675
point5 = bc_new_num (1,1);
@@ -87,6 +86,7 @@ bc_sqrt (bc_num *num, int scale)
8786
else
8887
{
8988
/* The number is greater than 1. Guess should start at 10^(exp/2). */
89+
bc_init_num(&guess);
9090
bc_int2num (&guess,10);
9191

9292
bc_int2num (&guess1,(*num)->n_len);

ext/bcmath/tests/bcsqrt.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ bcmath.scale=0
99
echo bcsqrt("9"),"\n";
1010
echo bcsqrt("9.444", 2),"\n";
1111
echo bcsqrt("1928372132132819737213", 5),"\n";
12+
echo bcsqrt("0.5", 5), "\n";
1213
?>
1314
--EXPECT--
1415
3
1516
3.07
1617
43913234134.28826
18+
0.70710

0 commit comments

Comments
 (0)