Skip to content

Commit 4c90bb2

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fixed GH-17398: bcmul memory leak (#17615)
2 parents 6945e60 + 5a4832f commit 4c90bb2

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

NEWS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.4.5
44

5+
- BCMath:
6+
. Fixed bug GH-17398 (bcmul memory leak). (SakiTakamachi)
7+
58
- DOM:
69
. Fixed bug GH-17609 (Typo in error message: Dom\NO_DEFAULT_NS instead of
710
Dom\HTML_NO_DEFAULT_NS). (nielsdos)
@@ -63,7 +66,7 @@ PHP NEWS
6366

6467
- Intl:
6568
. Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos)
66-
69+
6770
- Opcache:
6871
. Fixed bug GH-15981 (Segfault with frameless jumps and minimal JIT).
6972
(nielsdos)

ext/bcmath/bcmath.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ static PHP_GINIT_FUNCTION(bcmath)
109109
/* {{{ PHP_GSHUTDOWN_FUNCTION */
110110
static PHP_GSHUTDOWN_FUNCTION(bcmath)
111111
{
112-
_bc_free_num_ex(&bcmath_globals->_zero_, 1);
113-
_bc_free_num_ex(&bcmath_globals->_one_, 1);
114-
_bc_free_num_ex(&bcmath_globals->_two_, 1);
112+
bc_force_free_number(&bcmath_globals->_zero_);
113+
bc_force_free_number(&bcmath_globals->_one_);
114+
bc_force_free_number(&bcmath_globals->_two_);
115115
bcmath_globals->arena = NULL;
116116
bcmath_globals->arena_offset = 0;
117117
}

ext/bcmath/libbcmath/src/bcmath.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ typedef struct bc_struct {
8383

8484
void bc_init_numbers(void);
8585

86+
void bc_force_free_number(bc_num *num);
87+
8688
bc_num _bc_new_num_ex(size_t length, size_t scale, bool persistent);
8789

8890
bc_num _bc_new_num_nonzeroed_ex(size_t length, size_t scale, bool persistent);

ext/bcmath/libbcmath/src/init.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ void bc_init_numbers(void)
9797
BCG(_two_)->n_value[0] = 2;
9898
}
9999

100+
void bc_force_free_number(bc_num *num)
101+
{
102+
pefree((*num)->n_ptr, 1);
103+
pefree(*num, 1);
104+
*num = NULL;
105+
}
106+
100107

101108
/* Initialize a number NUM by making it a copy of zero. */
102109
void bc_init_num(bc_num *num)

ext/bcmath/tests/gh17398.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
GH-17398 (bcmul memory leak)
3+
--EXTENSIONS--
4+
bcmath
5+
--FILE--
6+
<?php
7+
bcmul('0', '0', 2147483647);
8+
?>
9+
--EXPECTF--
10+
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d

0 commit comments

Comments
 (0)