From 79eaffaaa7350af9022aec95014ade7819b841e6 Mon Sep 17 00:00:00 2001 From: Peter Tissen Date: Fri, 18 Apr 2014 13:28:27 +0200 Subject: [PATCH] copying class with pointers as member when deleting them in the desctructor is danger zone. --- rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp | 39 ++++++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp b/rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp index c82b257c12..d11a8b540d 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp @@ -21,21 +21,38 @@ struct sceNpTrophyInternalContext { // TODO std::string trp_name; - vfsStream* trp_stream; + std::unique_ptr trp_stream; - TROPUSRLoader* tropusr; + std::unique_ptr tropusr; +//TODO: remove the following code when Visual C++ no longer generates +//compiler errors for it. All of this should be auto-generated +#if _MSC_VER <= 1800 sceNpTrophyInternalContext() - : trp_stream(nullptr), - tropusr(nullptr) + : trp_stream(), + tropusr() { } - ~sceNpTrophyInternalContext() + sceNpTrophyInternalContext(sceNpTrophyInternalContext&& other) { - safe_delete(trp_stream); - safe_delete(tropusr); + std::swap(trp_stream,other.trp_stream); + std::swap(tropusr, other.tropusr); + std::swap(trp_name, other.trp_name); } + + sceNpTrophyInternalContext& operator =(sceNpTrophyInternalContext&& other) + { + std::swap(trp_stream, other.trp_stream); + std::swap(tropusr, other.tropusr); + std::swap(trp_name, other.trp_name); + return *this; + } + + sceNpTrophyInternalContext(sceNpTrophyInternalContext& other) = delete; + sceNpTrophyInternalContext& operator =(sceNpTrophyInternalContext& other) = delete; +#endif + }; struct sceNpTrophyInternal @@ -92,10 +109,10 @@ int sceNpTrophyCreateContext(mem32_t context, mem_ptr_t co if (stream && stream->IsOpened()) { - sceNpTrophyInternalContext ctxt; - ctxt.trp_stream = stream; + s_npTrophyInstance.contexts.emplace_back(); + sceNpTrophyInternalContext& ctxt = s_npTrophyInstance.contexts.back(); + ctxt.trp_stream.reset(stream); ctxt.trp_name = entry->name; - s_npTrophyInstance.contexts.push_back(ctxt); stream = nullptr; return CELL_OK; } @@ -178,7 +195,7 @@ int sceNpTrophyRegisterContext(u32 context, u32 handle, u32 statusCb_addr, u32 a std::string trophyUsrPath = trophyPath + "/TROPUSR.DAT"; std::string trophyConfPath = trophyPath + "/TROPCONF.SFM"; tropusr->Load(trophyUsrPath, trophyConfPath); - ctxt.tropusr = tropusr; + ctxt.tropusr.reset(tropusr); // TODO: Callbacks