Some memory management changes for Core

develop
Stoyan Gaydarov 2018-07-08 12:04:53 -07:00
parent b5ddde8475
commit 12c8046f90
3 changed files with 12 additions and 13 deletions

@ -1518,7 +1518,7 @@ Core::~Core()
}
Core::Core() :
d{new Private},
d(new Private),
script_path_mutex{},
HotkeyMutex{},
HotkeyCond{},
@ -1630,10 +1630,10 @@ bool Core::Init()
fatal(out.str());
return false;
}
p = new DFHack::Process(vif);
vinfo = p->getDescriptor();
std::unique_ptr<DFHack::Process> local_p(new DFHack::Process(vif));
vinfo = local_p->getDescriptor();
if(!vinfo || !p->isIdentified())
if(!vinfo || !local_p->isIdentified())
{
if (!Version::git_xml_match())
{
@ -1664,11 +1664,10 @@ bool Core::Init()
fatal("Not a known DF version.\n");
}
errorstate = true;
delete p;
p = NULL;
return false;
}
cerr << "Version: " << vinfo->getVersion() << endl;
p = std::move(local_p);
#if defined(_WIN32)
const OSType expected = OS_WINDOWS;
@ -2321,8 +2320,7 @@ int Core::Shutdown ( void )
}
allModules.clear();
memset(&(s_mods), 0, sizeof(s_mods));
delete d;
d = nullptr;
d.reset();
return -1;
}
@ -2751,7 +2749,7 @@ void ClassNameCheck::getKnownClassNames(std::vector<std::string> &names)
MemoryPatcher::MemoryPatcher(Process *p_) : p(p_)
{
if (!p)
p = Core::getInstance().p;
p = Core::getInstance().p.get();
}
MemoryPatcher::~MemoryPatcher()

@ -2521,7 +2521,7 @@ static const LuaWrapper::FunctionReg dfhack_internal_module[] = {
static int internal_getmd5(lua_State *L)
{
auto p = Core::getInstance().p;
auto& p = Core::getInstance().p;
if (p->getDescriptor()->getOS() == OS_WINDOWS)
luaL_error(L, "process MD5 not available on Windows");
lua_pushstring(L, p->getMD5().c_str());
@ -2530,7 +2530,7 @@ static int internal_getmd5(lua_State *L)
static int internal_getPE(lua_State *L)
{
auto p = Core::getInstance().p;
auto& p = Core::getInstance().p;
if (p->getDescriptor()->getOS() != OS_WINDOWS)
luaL_error(L, "process PE timestamp not available on non-Windows");
lua_pushinteger(L, p->getPE());

@ -30,6 +30,7 @@ distribution.
#include <vector>
#include <stack>
#include <map>
#include <memory>
#include <stdint.h>
#include "Console.h"
#include "modules/Graphic.h"
@ -191,7 +192,7 @@ namespace DFHack
DFHack::Console &getConsole() { return con; }
DFHack::Process * p;
std::unique_ptr<DFHack::Process> p;
DFHack::VersionInfo * vinfo;
DFHack::Windows::df_window * screen_window;
@ -209,7 +210,7 @@ namespace DFHack
~Core();
struct Private;
Private *d;
std::unique_ptr<Private> d;
bool Init();
int Update (void);