Fix memory leaks

This commit is contained in:
King_DuckZ 2022-05-15 19:19:56 +02:00
commit 692393285d
5 changed files with 24 additions and 23 deletions

View file

@ -77,7 +77,7 @@ namespace wren {
return ::WrenLoadModuleResult{
.source = source,
.onComplete = (cb->load_module_complete_fn ? &load_module_complete_fn : nullptr),
.userData = user_data
.userData = nullptr
};
}
@ -102,7 +102,11 @@ namespace wren {
assert(cb);
assert(cb->load_module_complete_fn and cb->config_obj and cb->owner);
(*cb->load_module_complete_fn)(*cb->config_obj, cb->owner, name);
//Documentation says result is the same object we returned from
//load_module_fn. It should then be safe to const_cast source,
//since it wasn't const when we got it there
char* const non_const_buff = const_cast<char*>(result.source);
(*cb->load_module_complete_fn)(*cb->config_obj, cb->owner, name, non_const_buff);
}
WrenForeignClassMethods foreign_class_fn (WrenVM* wvm, const char* module, const char* class_name) {