]> granicus.if.org Git - php/commitdiff
Add test instantiating all objects
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 1 Oct 2020 15:10:56 +0000 (17:10 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 1 Oct 2020 16:37:24 +0000 (18:37 +0200)
Intended to find issues in opaque object destructors.

Closes GH-6251.

Zend/tests/instantiate_all_classes.phpt [new file with mode: 0644]
ext/gd/gd.c
ext/openssl/openssl.c

diff --git a/Zend/tests/instantiate_all_classes.phpt b/Zend/tests/instantiate_all_classes.phpt
new file mode 100644 (file)
index 0000000..b8d8253
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Try to instantiate all classes without arguments
+--FILE--
+<?php
+
+foreach (get_declared_classes() as $class) {
+    try {
+        new $class;
+    } catch (Throwable) {}
+}
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
index 6f1ab3cf42b112e0929bba0c600f72987d52e68f..462b1259689b54ef5df4e363e4467d9a28c5a4ca 100644 (file)
@@ -199,9 +199,9 @@ zend_object *php_gd_image_object_create(zend_class_entry *class_type)
 static void php_gd_image_object_free(zend_object *intern)
 {
        php_gd_image_object *img_obj_ptr = php_gd_exgdimage_from_zobj_p(intern);
-       gdImageDestroy(img_obj_ptr->image);
-       img_obj_ptr->image = NULL;
-
+       if (img_obj_ptr->image) {
+               gdImageDestroy(img_obj_ptr->image);
+       }
        zend_object_std_dtor(intern);
 }
 
index 161396f4941e274a3a77b7378d8908486cb1dc9e..abaf88f15a38c4f806597baad93d69eb652c12ee 100644 (file)
@@ -233,10 +233,7 @@ static void php_openssl_pkey_free_obj(zend_object *object)
 {
        php_openssl_pkey_object *key_object = php_openssl_pkey_from_obj(object);
 
-       EVP_PKEY *pkey = key_object->pkey;
-       assert(pkey != NULL);
-       EVP_PKEY_free(pkey);
-
+       EVP_PKEY_free(key_object->pkey);
        zend_object_std_dtor(&key_object->std);
 }