From a50a32405de5c76f8876e5f479425f71d8e04c73 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Tue, 30 Aug 2016 09:47:33 +0300 Subject: [PATCH] Use weak_ptr for TypeDescriptor cross-links. Fixed total TypeDescriptor memory leak. --- lib/Connection.cpp | 4 +++- lib/Connection.h | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Connection.cpp b/lib/Connection.cpp index 2a491885a..d0907d827 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -474,8 +474,10 @@ std::vector CTypeList::castSequence(TypeInfoPtr from, Ty { auto typeNode = q.front(); q.pop(); - for(auto &nodeBase : upcast ? typeNode->parents : typeNode->children) + + for(auto & weakNode : (upcast ? typeNode->parents : typeNode->children) ) { + auto nodeBase = weakNode.lock(); if(!previous.count(nodeBase)) { previous[nodeBase] = typeNode; diff --git a/lib/Connection.h b/lib/Connection.h index ca084e8ba..28c7cedf9 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -156,11 +156,12 @@ class DLL_LINKAGE CTypeList: public boost::noncopyable public: struct TypeDescriptor; typedef std::shared_ptr TypeInfoPtr; + typedef std::weak_ptr WeakTypeInfoPtr; struct TypeDescriptor { ui16 typeID; const char *name; - std::vector children, parents; + std::vector children, parents; }; typedef boost::shared_mutex TMutex; typedef boost::unique_lock TUniqueLock;