Skip to content

Commit e7c0f4e

Browse files
authored
random: Rely on free(NULL) being safe for random status freeing (#10246)
* random: Rely on `free(NULL)` being safe for random status freeing * random: Restructure `php_random_status_free()` to not early-return
1 parent d7f6242 commit e7c0f4e

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

ext/random/random.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ static zend_object *php_random_randomizer_new(zend_class_entry *ce)
235235
static void randomizer_free_obj(zend_object *object) {
236236
php_random_randomizer *randomizer = php_random_randomizer_from_obj(object);
237237

238-
if (randomizer->is_userland_algo && randomizer->status) {
238+
if (randomizer->is_userland_algo) {
239239
php_random_status_free(randomizer->status, false);
240240
}
241241

@@ -262,9 +262,10 @@ PHPAPI php_random_status *php_random_status_copy(const php_random_algo *algo, ph
262262

263263
PHPAPI void php_random_status_free(php_random_status *status, const bool persistent)
264264
{
265-
if (status->state) {
265+
if (status != NULL) {
266266
pefree(status->state, persistent);
267267
}
268+
268269
pefree(status, persistent);
269270
}
270271

@@ -286,10 +287,7 @@ PHPAPI void php_random_engine_common_free_object(zend_object *object)
286287
{
287288
php_random_engine *engine = php_random_engine_from_obj(object);
288289

289-
if (engine->status) {
290-
php_random_status_free(engine->status, false);
291-
}
292-
290+
php_random_status_free(engine->status, false);
293291
zend_object_std_dtor(object);
294292
}
295293

0 commit comments

Comments
 (0)