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

@ -102,12 +102,16 @@ System.print("You have %(cale.appointment_count()) appointment(s)")
char* load_module_fn(wren::VM* vm, std::string_view module_name) {
if (module_name == "calendar") {
constexpr const std::size_t buff_sz = sizeof(g_calendar_src);
char* const buff = static_cast<char*>(MyConf::reallocate_fn(nullptr, buff_sz));
char* const buff = new char[buff_sz];
std::copy(g_calendar_src, g_calendar_src + buff_sz / sizeof(g_calendar_src[0]), buff);
return buff;
}
return nullptr;
}
void load_module_complete_fn(wren::VM*, std::string_view, char* buffer) {
delete[] buffer;
}
};
} //unnamed namespace

View file

@ -81,9 +81,10 @@ System.print("vec3 modified by scripting: <%(vec3.x), %(vec3.y), %(vec3.z)>")
public:
char* load_module_fn(wren::VM* vm, std::string_view module_name) {
if (module_name == "math_vector") {
constexpr const std::size_t buff_sz = g_math_vector_src.size();
constexpr const std::size_t buff_sz = g_math_vector_src.size() + 1;
char* const buff = static_cast<char*>(MyConf::reallocate_fn(nullptr, buff_sz));
std::copy(g_math_vector_src.cbegin(), g_math_vector_src.cend(), buff);
buff[buff_sz - 1] = '\0';
return buff;
}
return nullptr;