summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-11-12 11:37:54 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-11-12 11:37:54 +0100
commit3d2819e491aee6a504a54e15f6eafa9707a1ce67 (patch)
treeab4c1dc4de92947cdd9fe29dc934af8af0608a83
parentd033d5c07a25ab36a9138f35a7a02f62822a9e4d (diff)
downloadphp-git-3d2819e491aee6a504a54e15f6eafa9707a1ce67.tar.gz
Fix memory leak with bcsqrt on number 0<X<1
-rw-r--r--ext/bcmath/libbcmath/src/sqrt.c2
-rw-r--r--ext/bcmath/tests/bcsqrt.phpt2
2 files changed, 3 insertions, 1 deletions
diff --git a/ext/bcmath/libbcmath/src/sqrt.c b/ext/bcmath/libbcmath/src/sqrt.c
index 6358ff7bcd..96cff29475 100644
--- a/ext/bcmath/libbcmath/src/sqrt.c
+++ b/ext/bcmath/libbcmath/src/sqrt.c
@@ -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);
diff --git a/ext/bcmath/tests/bcsqrt.phpt b/ext/bcmath/tests/bcsqrt.phpt
index 9f4a8ec6a5..b2a8d8adbc 100644
--- a/ext/bcmath/tests/bcsqrt.phpt
+++ b/ext/bcmath/tests/bcsqrt.phpt
@@ -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