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.
This commit is contained in:
Niels Dossche 2024-05-01 13:49:58 +02:00
parent f4dbe2390d
commit 3215e86a11

View file

@ -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;