1
0
Fork 0

Merge pull request #102131 from dsnopek/classdb-bind-method-custom-leak

Fix memory leak when `ClassDB::bind_method_custom()` fails
This commit is contained in:
Thaddeus Crews 2025-01-30 11:39:04 -06:00
commit 699237d243
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
1 changed files with 9 additions and 5 deletions

View File

@ -1866,9 +1866,12 @@ void ClassDB::_bind_compatibility(ClassInfo *type, MethodBind *p_method) {
void ClassDB::_bind_method_custom(const StringName &p_class, MethodBind *p_method, bool p_compatibility) {
OBJTYPE_WLOCK;
StringName method_name = p_method->get_name();
ClassInfo *type = classes.getptr(p_class);
if (!type) {
ERR_FAIL_MSG(vformat("Couldn't bind custom method '%s' for instance '%s'.", p_method->get_name(), p_class));
memdelete(p_method);
ERR_FAIL_MSG(vformat("Couldn't bind custom method '%s' for instance '%s'.", method_name, p_class));
}
if (p_compatibility) {
@ -1876,16 +1879,17 @@ void ClassDB::_bind_method_custom(const StringName &p_class, MethodBind *p_metho
return;
}
if (type->method_map.has(p_method->get_name())) {
if (type->method_map.has(method_name)) {
// overloading not supported
ERR_FAIL_MSG(vformat("Method already bound '%s::%s'.", p_class, p_method->get_name()));
memdelete(p_method);
ERR_FAIL_MSG(vformat("Method already bound '%s::%s'.", p_class, method_name));
}
#ifdef DEBUG_METHODS_ENABLED
type->method_order.push_back(p_method->get_name());
type->method_order.push_back(method_name);
#endif
type->method_map[p_method->get_name()] = p_method;
type->method_map[method_name] = p_method;
}
MethodBind *ClassDB::_bind_vararg_method(MethodBind *p_bind, const StringName &p_name, const Vector<Variant> &p_default_args, bool p_compatibility) {