Merge pull request #21411 from Crazy-P/fixes-several-resource-leaks
Fixes several resource leaks listed on coverity
This commit is contained in:
commit
282c0483c9
6 changed files with 48 additions and 6 deletions
|
@ -1008,7 +1008,10 @@ RID RasterizerSceneGLES3::light_instance_create(RID p_light) {
|
||||||
light_instance->light = p_light;
|
light_instance->light = p_light;
|
||||||
light_instance->light_ptr = storage->light_owner.getornull(p_light);
|
light_instance->light_ptr = storage->light_owner.getornull(p_light);
|
||||||
|
|
||||||
|
if (!light_instance->light_ptr) {
|
||||||
|
memdelete(light_instance);
|
||||||
ERR_FAIL_COND_V(!light_instance->light_ptr, RID());
|
ERR_FAIL_COND_V(!light_instance->light_ptr, RID());
|
||||||
|
}
|
||||||
|
|
||||||
light_instance->self = light_instance_owner.make_rid(light_instance);
|
light_instance->self = light_instance_owner.make_rid(light_instance);
|
||||||
|
|
||||||
|
|
|
@ -6998,7 +6998,10 @@ RID RasterizerStorageGLES3::canvas_light_shadow_buffer_create(int p_width) {
|
||||||
//printf("errnum: %x\n",status);
|
//printf("errnum: %x\n",status);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
|
||||||
|
|
||||||
|
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
|
memdelete(cls);
|
||||||
ERR_FAIL_COND_V(status != GL_FRAMEBUFFER_COMPLETE, RID());
|
ERR_FAIL_COND_V(status != GL_FRAMEBUFFER_COMPLETE, RID());
|
||||||
|
}
|
||||||
|
|
||||||
return canvas_light_shadow_owner.make_rid(cls);
|
return canvas_light_shadow_owner.make_rid(cls);
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,8 +126,11 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco
|
||||||
GDScriptLanguage::singleton->lock->unlock();
|
GDScriptLanguage::singleton->lock->unlock();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (r_error.error != Variant::CallError::CALL_OK) {
|
||||||
|
memdelete(instance);
|
||||||
ERR_FAIL_COND_V(r_error.error != Variant::CallError::CALL_OK, NULL); //error constructing
|
ERR_FAIL_COND_V(r_error.error != Variant::CallError::CALL_OK, NULL); //error constructing
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//@TODO make thread safe
|
//@TODO make thread safe
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -719,22 +722,36 @@ Error GDScript::load_byte_code(const String &p_path) {
|
||||||
|
|
||||||
FileAccess *fa = FileAccess::open(p_path, FileAccess::READ);
|
FileAccess *fa = FileAccess::open(p_path, FileAccess::READ);
|
||||||
ERR_FAIL_COND_V(!fa, ERR_CANT_OPEN);
|
ERR_FAIL_COND_V(!fa, ERR_CANT_OPEN);
|
||||||
|
|
||||||
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
|
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
|
||||||
ERR_FAIL_COND_V(!fae, ERR_CANT_OPEN);
|
ERR_FAIL_COND_V(!fae, ERR_CANT_OPEN);
|
||||||
|
|
||||||
Vector<uint8_t> key;
|
Vector<uint8_t> key;
|
||||||
key.resize(32);
|
key.resize(32);
|
||||||
for (int i = 0; i < key.size(); i++) {
|
for (int i = 0; i < key.size(); i++) {
|
||||||
key.write[i] = script_encryption_key[i];
|
key.write[i] = script_encryption_key[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
Error err = fae->open_and_parse(fa, key, FileAccessEncrypted::MODE_READ);
|
Error err = fae->open_and_parse(fa, key, FileAccessEncrypted::MODE_READ);
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
fa->close();
|
||||||
|
memdelete(fa);
|
||||||
|
memdelete(fae);
|
||||||
|
|
||||||
ERR_FAIL_COND_V(err, err);
|
ERR_FAIL_COND_V(err, err);
|
||||||
|
}
|
||||||
|
|
||||||
bytecode.resize(fae->get_len());
|
bytecode.resize(fae->get_len());
|
||||||
fae->get_buffer(bytecode.ptrw(), bytecode.size());
|
fae->get_buffer(bytecode.ptrw(), bytecode.size());
|
||||||
|
fae->close();
|
||||||
memdelete(fae);
|
memdelete(fae);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
bytecode = FileAccess::get_file_as_array(p_path);
|
bytecode = FileAccess::get_file_as_array(p_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
ERR_FAIL_COND_V(bytecode.size() == 0, ERR_PARSE_ERROR);
|
ERR_FAIL_COND_V(bytecode.size() == 0, ERR_PARSE_ERROR);
|
||||||
path = p_path;
|
path = p_path;
|
||||||
|
|
||||||
|
@ -2097,7 +2114,7 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_ori
|
||||||
Error err = script->load_byte_code(p_path);
|
Error err = script->load_byte_code(p_path);
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
|
memdelete(script);
|
||||||
ERR_FAIL_COND_V(err != OK, RES());
|
ERR_FAIL_COND_V(err != OK, RES());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2105,7 +2122,7 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_ori
|
||||||
Error err = script->load_source_code(p_path);
|
Error err = script->load_source_code(p_path);
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
|
memdelete(script);
|
||||||
ERR_FAIL_COND_V(err != OK, RES());
|
ERR_FAIL_COND_V(err != OK, RES());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2120,6 +2137,7 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_ori
|
||||||
|
|
||||||
return scriptres;
|
return scriptres;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceFormatLoaderGDScript::get_recognized_extensions(List<String> *p_extensions) const {
|
void ResourceFormatLoaderGDScript::get_recognized_extensions(List<String> *p_extensions) const {
|
||||||
|
|
||||||
p_extensions->push_back("gd");
|
p_extensions->push_back("gd");
|
||||||
|
|
|
@ -1322,6 +1322,8 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
|
||||||
|
|
||||||
int ret = _parse_expression(codegen, op, p_stack_level);
|
int ret = _parse_expression(codegen, op, p_stack_level);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
memdelete(id);
|
||||||
|
memdelete(op);
|
||||||
return ERR_PARSE_ERROR;
|
return ERR_PARSE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1341,6 +1343,8 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
|
||||||
// compile the condition
|
// compile the condition
|
||||||
int ret = _parse_expression(codegen, branch.compiled_pattern, p_stack_level);
|
int ret = _parse_expression(codegen, branch.compiled_pattern, p_stack_level);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
memdelete(id);
|
||||||
|
memdelete(op);
|
||||||
return ERR_PARSE_ERROR;
|
return ERR_PARSE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1353,6 +1357,8 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
|
||||||
|
|
||||||
Error err = _parse_block(codegen, branch.body, p_stack_level, p_break_addr, continue_addr);
|
Error err = _parse_block(codegen, branch.body, p_stack_level, p_break_addr, continue_addr);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
memdelete(id);
|
||||||
|
memdelete(op);
|
||||||
return ERR_PARSE_ERROR;
|
return ERR_PARSE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1364,6 +1370,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
|
||||||
|
|
||||||
codegen.opcodes.write[break_addr + 1] = codegen.opcodes.size();
|
codegen.opcodes.write[break_addr + 1] = codegen.opcodes.size();
|
||||||
|
|
||||||
|
memdelete(id);
|
||||||
|
memdelete(op);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case GDScriptParser::ControlFlowNode::CF_IF: {
|
case GDScriptParser::ControlFlowNode::CF_IF: {
|
||||||
|
|
|
@ -205,6 +205,8 @@ Error RegEx::compile(const String &p_pattern) {
|
||||||
|
|
||||||
code = pcre2_compile_16(p, pattern.length(), flags, &err, &offset, cctx);
|
code = pcre2_compile_16(p, pattern.length(), flags, &err, &offset, cctx);
|
||||||
|
|
||||||
|
pcre2_compile_context_free_16(cctx);
|
||||||
|
|
||||||
if (!code) {
|
if (!code) {
|
||||||
PCRE2_UCHAR16 buf[256];
|
PCRE2_UCHAR16 buf[256];
|
||||||
pcre2_get_error_message_16(err, buf, 256);
|
pcre2_get_error_message_16(err, buf, 256);
|
||||||
|
@ -221,6 +223,8 @@ Error RegEx::compile(const String &p_pattern) {
|
||||||
|
|
||||||
code = pcre2_compile_32(p, pattern.length(), flags, &err, &offset, cctx);
|
code = pcre2_compile_32(p, pattern.length(), flags, &err, &offset, cctx);
|
||||||
|
|
||||||
|
pcre2_compile_context_free_32(cctx);
|
||||||
|
|
||||||
if (!code) {
|
if (!code) {
|
||||||
PCRE2_UCHAR32 buf[256];
|
PCRE2_UCHAR32 buf[256];
|
||||||
pcre2_get_error_message_32(err, buf, 256);
|
pcre2_get_error_message_32(err, buf, 256);
|
||||||
|
@ -285,6 +289,8 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end)
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
pcre2_match_data_free_32(match);
|
pcre2_match_data_free_32(match);
|
||||||
|
pcre2_match_context_free_32(mctx);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1591,8 +1591,11 @@ public:
|
||||||
String apkfname = "main." + itos(version_code) + "." + get_package_name(package_name) + ".obb";
|
String apkfname = "main." + itos(version_code) + "." + get_package_name(package_name) + ".obb";
|
||||||
String fullpath = p_path.get_base_dir().plus_file(apkfname);
|
String fullpath = p_path.get_base_dir().plus_file(apkfname);
|
||||||
err = save_pack(p_preset, fullpath);
|
err = save_pack(p_preset, fullpath);
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
|
unzClose(pkg);
|
||||||
EditorNode::add_io_error("Could not write expansion package file: " + apkfname);
|
EditorNode::add_io_error("Could not write expansion package file: " + apkfname);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue