[php-src] master: Avoid double allocation in _bc_new_num_ex

From: Date: Wed, 01 May 2024 14:18:45 +0000
Subject: [php-src] master: Avoid double allocation in _bc_new_num_ex
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-128292@lists.php.net to get a copy of this message
Author: Niels Dossche (nielsdos) Date: 2024-05-01T16:18:37+02:00 Commit: https://github.com/php/php-src/commit/3215e86a11580e77f53660499e9c7e403f08ea5c Raw diff: https://github.com/php/php-src/commit/3215e86a11580e77f53660499e9c7e403f08ea5c.diff Avoid double allocation in _bc_new_num_ex Since the two allocations are tied together anyway, we can just use a single allocation. Moreover, this actually seemed like the intention because the bc_struct allocation already accounted for the length and scale. Changed paths: M ext/bcmath/libbcmath/src/init.c Diff: diff --git a/ext/bcmath/libbcmath/src/init.c b/ext/bcmath/libbcmath/src/init.c index cef55324689f..3c82af5821c7 100644 --- a/ext/bcmath/libbcmath/src/init.c +++ b/ext/bcmath/libbcmath/src/init.c @@ -39,13 +39,12 @@ bc_num _bc_new_num_ex(size_t length, size_t scale, bool persistent) { /* PHP Change: malloc() -> pemalloc(), removed free_list code */ - bc_num temp = (bc_num) safe_pemalloc(1, sizeof(bc_struct) + length, scale, persistent); + bc_num temp = safe_pemalloc(1, sizeof(bc_struct) + length, scale, persistent); temp->n_sign = PLUS; temp->n_len = length; temp->n_scale = scale; temp->n_refs = 1; - /* PHP Change: malloc() -> pemalloc() */ - temp->n_ptr = (char *) safe_pemalloc(1, length, scale, persistent); + temp->n_ptr = (char *) temp + sizeof(bc_struct); temp->n_value = temp->n_ptr; memset(temp->n_ptr, 0, length + scale); return temp; @@ -61,10 +60,6 @@ void _bc_free_num_ex(bc_num *num, bool persistent) } (*num)->n_refs--; if ((*num)->n_refs == 0) { - if ((*num)->n_ptr) { - /* PHP Change: free() -> pefree(), removed free_list code */ - pefree((*num)->n_ptr, persistent); - } pefree(*num, persistent); } *num = NULL;

« previous php.cvs (#128292) next »