From 54f5c95832921b72583144e53fa45318a60e9ff9 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 7 Jan 2016 11:14:00 +0100 Subject: COMMON: Make FSNode(AbstractFSNode *) private again. This also fixes a memory leak in OSystem_iOS7::addSysArchivesToSearchSet. --- backends/fs/abstract-fs.h | 14 ++++++++++++++ backends/platform/ios7/ios7_osys_main.cpp | 3 +-- common/fs.h | 11 ++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/backends/fs/abstract-fs.h b/backends/fs/abstract-fs.h index 34a8120caa..dcfdc08975 100644 --- a/backends/fs/abstract-fs.h +++ b/backends/fs/abstract-fs.h @@ -83,6 +83,20 @@ protected: static const char *lastPathComponent(const Common::String &str, const char sep); public: + /** + * Construct a FSNode object from an AbstractFSNode object. + * + * This is a helper to create Common::FSNode objects when the backend's + * FileSystemFactory cannot create the given AbstractFSNode object itself. + * All other code is supposed to use Common::FSNode's constructor itself. + * + * @param realNode Pointer to a heap allocated instance. FSNode will take + * ownership of the pointer. + */ + static Common::FSNode makeFSNode(AbstractFSNode *realNode) { + return Common::FSNode(realNode); + } + /** * Destructor. */ diff --git a/backends/platform/ios7/ios7_osys_main.cpp b/backends/platform/ios7/ios7_osys_main.cpp index 37fa34ce33..f169dbb1b2 100644 --- a/backends/platform/ios7/ios7_osys_main.cpp +++ b/backends/platform/ios7/ios7_osys_main.cpp @@ -301,8 +301,7 @@ void OSystem_iOS7::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) Common::String bundlePath((const char *)buf); #ifdef IPHONE_SANDBOXED POSIXFilesystemNode *posixNode = new POSIXFilesystemNode(bundlePath); - Common::FSNode *node = new Common::FSNode(posixNode); - s.add("__IOS_BUNDLE__", new Common::FSDirectory(*node), priority); + s.add("__IOS_BUNDLE__", new Common::FSDirectory(AbstractFSNode::makeFSNode(posixNode)), priority); #else s.add("__IOS_BUNDLE__", new Common::FSDirectory(bundlePath), priority); #endif diff --git a/common/fs.h b/common/fs.h index 66e98444d6..f516bf7a9c 100644 --- a/common/fs.h +++ b/common/fs.h @@ -57,12 +57,17 @@ class FSList : public Array {}; */ class FSNode : public ArchiveMember { private: + friend class ::AbstractFSNode; SharedPtr _realNode; - -public: - // WARNING: Use this constructor with care! FSNode takes the ownership of the pointer and will delete it at some point. + /** + * Construct a FSNode from a backend's AbstractFSNode implementation. + * + * @param realNode Pointer to a heap allocated instance. FSNode will take + * ownership of the pointer. + */ FSNode(AbstractFSNode *realNode); +public: /** * Flag to tell listDir() which kind of files to list. */ -- cgit v1.2.3