From 5e9b37d52c1bbc5d3486bb9637b0444f3fdeb978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 24 Nov 2015 00:58:09 +0100 Subject: [PATCH] Fixed small memory leaks and uninitialized values --- src/definition/AtmosphereDefinition.cpp | 1 + src/render/opengl/OpenGLSharedState.cpp | 9 ++++++++- src/render/opengl/OpenGLSharedState.h | 1 + src/system/Thread.cpp | 3 +++ src/system/Thread.h | 2 ++ src/tests/GodRaysSampler_Test.cpp | 1 + src/tests/Layers_Test.cpp | 5 +++++ 7 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/definition/AtmosphereDefinition.cpp b/src/definition/AtmosphereDefinition.cpp index 5ab7f1d..84e6280 100644 --- a/src/definition/AtmosphereDefinition.cpp +++ b/src/definition/AtmosphereDefinition.cpp @@ -7,6 +7,7 @@ AtmosphereDefinition::AtmosphereDefinition(DefinitionNode *parent) : DefinitionNode(parent, "atmosphere", "atmosphere") { + model = ATMOSPHERE_MODEL_DISABLED; godrays = new GodRaysDefinition(this); daytime = new FloatNode(this, "daytime"); humidity = new FloatNode(this, "humidity"); diff --git a/src/render/opengl/OpenGLSharedState.cpp b/src/render/opengl/OpenGLSharedState.cpp index f374277..f5a9d8c 100644 --- a/src/render/opengl/OpenGLSharedState.cpp +++ b/src/render/opengl/OpenGLSharedState.cpp @@ -3,6 +3,13 @@ OpenGLSharedState::OpenGLSharedState() { } +paysages::opengl::OpenGLSharedState::~OpenGLSharedState() +{ + for (const auto &pair : variables) { + delete pair.second; + } +} + void OpenGLSharedState::apply(OpenGLShaderProgram *program, int &texture_unit) { for (const auto &pair : variables) { pair.second->apply(program, texture_unit); @@ -11,7 +18,7 @@ void OpenGLSharedState::apply(OpenGLShaderProgram *program, int &texture_unit) { OpenGLVariable *OpenGLSharedState::get(const std::string &name) { OpenGLVariable *&var = variables[name]; - if (var == 0) { + if (var == NULL) { var = new OpenGLVariable(name); } return var; diff --git a/src/render/opengl/OpenGLSharedState.h b/src/render/opengl/OpenGLSharedState.h index 8e206c7..095448c 100644 --- a/src/render/opengl/OpenGLSharedState.h +++ b/src/render/opengl/OpenGLSharedState.h @@ -15,6 +15,7 @@ namespace opengl { class OPENGLSHARED_EXPORT OpenGLSharedState { public: OpenGLSharedState(); + ~OpenGLSharedState(); /*! * \brief Apply the stored variables to the bound program. diff --git a/src/system/Thread.cpp b/src/system/Thread.cpp index ab9a7aa..fca9c37 100644 --- a/src/system/Thread.cpp +++ b/src/system/Thread.cpp @@ -3,6 +3,9 @@ Thread::Thread(ThreadFunction function) : data(0), result(0), function(function) { } +Thread::~Thread() { +} + void Thread::start(void *data) { this->data = data; QThread::start(); diff --git a/src/system/Thread.h b/src/system/Thread.h index 61f9b9a..96fd96f 100644 --- a/src/system/Thread.h +++ b/src/system/Thread.h @@ -24,6 +24,8 @@ class SYSTEMSHARED_EXPORT Thread : private QThread { */ Thread(ThreadFunction function = 0); + virtual ~Thread(); + /** * Start the thread, with custom data. */ diff --git a/src/tests/GodRaysSampler_Test.cpp b/src/tests/GodRaysSampler_Test.cpp index 7e156e6..8ac3de4 100644 --- a/src/tests/GodRaysSampler_Test.cpp +++ b/src/tests/GodRaysSampler_Test.cpp @@ -60,6 +60,7 @@ TEST(GodRaysSampler, setQuality) { class GodRayLightSource : public LightSource { virtual bool getLightsAt(std::vector &result, const Vector3 &location) const override { LightComponent light; + light.direction = VECTOR_DOWN; light.altered = true; light.color = Color(fabs(location.x), fabs(location.y), fabs(location.z)); result.push_back(light); diff --git a/src/tests/Layers_Test.cpp b/src/tests/Layers_Test.cpp index 25d1419..8c8c06c 100644 --- a/src/tests/Layers_Test.cpp +++ b/src/tests/Layers_Test.cpp @@ -4,6 +4,7 @@ #include "PackStream.h" #include "DiffManager.h" #include "IntNode.h" +#include "DefinitionDiff.h" static DefinitionNode *_construc1(Layers *, const std::string &name) { return new DefinitionNode(NULL, name); @@ -193,4 +194,8 @@ TEST(Layers, generateInitDiffs) { EXPECT_EQ("l1", layers1.getLayer(0)->getName()); EXPECT_EQ("l2", layers1.getLayer(1)->getName()); EXPECT_EQ("l3", layers1.getLayer(2)->getName()); + + for (auto diff : diffs) { + delete diff; + } }