From 6d33ad248d49258342cd7f56efa2adf64b414f11 Mon Sep 17 00:00:00 2001 From: Roman Melnik Date: Fri, 23 Mar 2012 22:08:02 +0200 Subject: [PATCH] Fix memory leak in getIdentity method Replace static pointer and new() operator with normal static variable --- components/nif/nif_types.hpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/components/nif/nif_types.hpp b/components/nif/nif_types.hpp index ce7a0de62..83f912bfd 100644 --- a/components/nif/nif_types.hpp +++ b/components/nif/nif_types.hpp @@ -62,17 +62,18 @@ struct Transformation static const Transformation* getIdentity() { - static Transformation* identity = NULL; - if (NULL == identity) + static Transformation identity; + static bool iset = false; + if (!iset) { - identity = new Transformation(); - identity->scale = 1.0f; - identity->rotation.v[0].array[0] = 1.0f; - identity->rotation.v[1].array[1] = 1.0f; - identity->rotation.v[2].array[2] = 1.0f; + identity.scale = 1.0f; + identity.rotation.v[0].array[0] = 1.0f; + identity.rotation.v[1].array[1] = 1.0f; + identity.rotation.v[2].array[2] = 1.0f; + iset = true; } - return identity; + return &identity; } }; #pragma pack(pop)