From edbbf493f807ed94b9b32cfb7463f9b7f8f27852 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 6 Dec 2015 23:15:51 -0500 Subject: DiscIO: Make factory methods return unique_ptrs Rather than rely on the developer to do the right thing, just make the default behavior safely deallocate resources. If shared semantics are ever needed in the future, the constructor that takes a unique_ptr for shared_ptr can be used. --- Source/Core/DiscIO/Filesystem.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'Source/Core/DiscIO/Filesystem.cpp') diff --git a/Source/Core/DiscIO/Filesystem.cpp b/Source/Core/DiscIO/Filesystem.cpp index c723569088..3ca1f70f04 100644 --- a/Source/Core/DiscIO/Filesystem.cpp +++ b/Source/Core/DiscIO/Filesystem.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include #include "DiscIO/Filesystem.h" #include "DiscIO/FileSystemGCWii.h" @@ -17,20 +18,17 @@ IFileSystem::~IFileSystem() {} -IFileSystem* CreateFileSystem(const IVolume* _rVolume) +std::unique_ptr CreateFileSystem(const IVolume* volume) { - IFileSystem* pFileSystem = new CFileSystemGCWii(_rVolume); + std::unique_ptr filesystem = std::make_unique(volume); - if (!pFileSystem) + if (!filesystem) return nullptr; - if (!pFileSystem->IsValid()) - { - delete pFileSystem; - pFileSystem = nullptr; - } + if (!filesystem->IsValid()) + filesystem.reset(); - return pFileSystem; + return filesystem; } } // namespace -- cgit v1.2.3