Skip to content

Commit 2c0a231

Browse files
fix double free call, which caused memory-corruption
1 parent 87b079a commit 2c0a231

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

zend/classimpl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Implementation file for the ClassImpl class
55
*
66
* @author Emiel Bruijntjes <[email protected]>
7-
* @copyright 2014 - 2019 Copernica BV
7+
* @copyright 2014 - 2024 Copernica BV
88
*/
99
#include "includes.h"
1010
#include <cstring>
@@ -207,7 +207,10 @@ zend_function *ClassImpl::getMethod(zend_object **object, zend_string *method, c
207207
// had an implementation here that used a static variable, and that worked too,
208208
// but we'll follow thread safe implementation of the Zend engine here, although
209209
// it is strange to allocate and free memory in one and the same method call (free()
210-
// call happens in call_method())
210+
// call happens in call_method()) (2024-10-13 extra info: the method_exists()
211+
// function and our own Value::isCallable() method expect this to be emalloc()-
212+
// allocated buffer, because they both call zend_free_trampoline() (which is
213+
// effectively an efree() call) on the returned function-structure)
211214
auto *data = (CallData *)emalloc(sizeof(CallData));
212215
auto *function = &data->func;
213216

zend/value.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,11 @@ bool Value::isCallable(const char *name)
891891
bool result = func->common.scope == zend_ce_closure && zend_string_equals_cstr(methodname.value(), ZEND_INVOKE_FUNC_NAME, ::strlen(ZEND_INVOKE_FUNC_NAME));
892892
#endif
893893

894-
// free resources (still don't get this code, copied from zend_builtin_functions.c)
895-
zend_string_release(func->common.function_name);
894+
// in method_exists(), there is also a zend_string_release() call here, but I dont think we
895+
// need it here, because the methodname is already cleanup by the destructor of the LowerCase class
896+
//zend_string_release(func->common.function_name);
897+
898+
// free resources, just like method_exists() does
896899
zend_free_trampoline(func);
897900

898901
// done

0 commit comments

Comments
 (0)