From 9ddcfa8e7dbc293ea3b317090378f1dfdef88c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Thu, 16 Apr 2015 23:25:03 +0200 Subject: [PATCH] Fix memory leak --- example/doc_entity.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/example/doc_entity.cpp b/example/doc_entity.cpp index 02122a6..531f229 100644 --- a/example/doc_entity.cpp +++ b/example/doc_entity.cpp @@ -27,7 +27,15 @@ class some_entity : public entity {/**/}; //Definition of the intrusive list -typedef list entity_list; +struct entity_list : list +{ + ~entity_list() + { + // entity's destructor removes itself from the global list implicitly + while (!this->empty()) + delete &this->front(); + } +}; //A global list entity_list global_list; @@ -40,14 +48,6 @@ entity::~entity() void insert_some_entity() { global_list.push_back (*new some_entity(/*...*/)); } -//Function to clear an entity from the intrusive global list -void clear_list () -{ - // entity's destructor removes itself from the global list implicitly - while (!global_list.empty()) - delete &global_list.front(); -} - int main() { //Insert some new entities @@ -57,4 +57,4 @@ int main() return 0; } -//] +//]