From 1f209bfc41ef5f2cd63c961262d5d6fe3e03b55a Mon Sep 17 00:00:00 2001 From: qarmin Date: Mon, 2 Mar 2020 19:17:20 +0100 Subject: [PATCH] Fixes bugs found by Sonarcloud and Coverity --- core/io/resource_format_binary.cpp | 2 ++ core/io/resource_loader.cpp | 1 + core/io/resource_loader.h | 2 +- core/message_queue.cpp | 5 ++++- core/variant_parser.h | 2 +- drivers/vulkan/rendering_device_vulkan.cpp | 5 ++++- scene/resources/resource_format_text.cpp | 12 ++++++------ servers/visual/rasterizer.h | 1 + .../visual/rasterizer_rd/rasterizer_effects_rd.cpp | 2 +- .../visual/rasterizer_rd/rasterizer_storage_rd.cpp | 6 ++++-- 10 files changed, 25 insertions(+), 13 deletions(-) diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 54b75cc29d6..efd452191a0 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1008,7 +1008,9 @@ String ResourceLoaderBinary::recognize(FileAccess *p_f) { ResourceLoaderBinary::ResourceLoaderBinary() : translation_remapped(false), + ver_format(0), f(NULL), + importmd_ofs(0), error(OK) { progress = nullptr; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 504dbe2d635..5dca8b3b896 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -538,6 +538,7 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p if (r_error) { *r_error = err; } + thread_load_mutex->unlock(); return RES(); } thread_load_mutex->unlock(); diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 3b7a27f5519..ea89917a5fb 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -116,7 +116,7 @@ private: String type_hint; float progress = 0.0; ThreadLoadStatus status = THREAD_LOAD_IN_PROGRESS; - Error error; + Error error = OK; RES resource; bool xl_remapped = false; bool use_sub_threads = false; diff --git a/core/message_queue.cpp b/core/message_queue.cpp index 235003627ee..37207483fe5 100644 --- a/core/message_queue.cpp +++ b/core/message_queue.cpp @@ -268,7 +268,10 @@ void MessageQueue::flush() { //using reverse locking strategy _THREAD_SAFE_LOCK_ - ERR_FAIL_COND(flushing); //already flushing, you did something odd + if (flushing) { + _THREAD_SAFE_UNLOCK_ + ERR_FAIL_COND(flushing); //already flushing, you did something odd + } flushing = true; while (read_pos < buffer_end) { diff --git a/core/variant_parser.h b/core/variant_parser.h index ad0a4d6682c..d50842145cb 100644 --- a/core/variant_parser.h +++ b/core/variant_parser.h @@ -77,7 +77,7 @@ public: struct ResourceParser { - void *userdata; + void *userdata = nullptr; ParseResourceFunc func; ParseResourceFunc ext_func; ParseResourceFunc sub_func; diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index 2bf8a160915..3756d11815a 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -4182,7 +4182,10 @@ RenderingDeviceVulkan::DescriptorPool *RenderingDeviceVulkan::_descriptor_pool_a descriptor_pool_create_info.poolSizeCount = sizes.size(); descriptor_pool_create_info.pPoolSizes = sizes.ptr(); VkResult res = vkCreateDescriptorPool(device, &descriptor_pool_create_info, NULL, &pool->pool); - ERR_FAIL_COND_V(res, NULL); + if (res) { + memdelete(pool); + ERR_FAIL_COND_V(res, NULL); + } descriptor_pools[p_key].insert(pool); } diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index 97bd12c119c..238bdf05ef4 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -403,8 +403,6 @@ Ref ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars return Ref(); } } - - return packed_scene; } Error ResourceLoaderText::load() { @@ -671,10 +669,6 @@ Error ResourceLoaderText::load() { return error; } } - - if (progress) { - *progress = resource_current / float(resources_total); - } } //for scene files @@ -731,9 +725,15 @@ void ResourceLoaderText::set_translation_remapped(bool p_remapped) { } ResourceLoaderText::ResourceLoaderText() { + resources_total = 0; + resource_current = 0; + use_sub_threads = false; + progress = nullptr; + lines = false; translation_remapped = false; use_sub_threads = false; + error = OK; } ResourceLoaderText::~ResourceLoaderText() { diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 3a219ec7e3b..0a55c781334 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -1171,6 +1171,7 @@ public: Command *n = c->next; if (c == commands) { memdelete(commands); + commands = NULL; } else { c->~Command(); } diff --git a/servers/visual/rasterizer_rd/rasterizer_effects_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_effects_rd.cpp index f4d59e9e54d..01cab76128f 100644 --- a/servers/visual/rasterizer_rd/rasterizer_effects_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_effects_rd.cpp @@ -1077,7 +1077,7 @@ RasterizerEffectsRD::~RasterizerEffectsRD() { RD::get_singleton()->free(filter.image_uniform_set); } - if (RD::get_singleton()->uniform_set_is_valid(filter.image_uniform_set)) { + if (RD::get_singleton()->uniform_set_is_valid(filter.uniform_set)) { RD::get_singleton()->free(filter.uniform_set); } diff --git a/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp index 15cbc61b76e..52cefa7511e 100644 --- a/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp @@ -1906,8 +1906,10 @@ void RasterizerStorageRD::mesh_add_surface(RID p_mesh, const VS::SurfaceData &p_ for (int i = 0; i < p_surface.blend_shapes.size(); i++) { - ERR_FAIL_COND(p_surface.blend_shapes[i].size() != p_surface.vertex_data.size()); - + if (p_surface.blend_shapes[i].size() != p_surface.vertex_data.size()) { + memdelete(s); + ERR_FAIL_COND(p_surface.blend_shapes[i].size() != p_surface.vertex_data.size()); + } RID vertex_buffer = RD::get_singleton()->vertex_buffer_create(p_surface.blend_shapes[i].size(), p_surface.blend_shapes[i]); s->blend_shapes.push_back(vertex_buffer); }