diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2013-08-06 03:31:59 +0200 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2013-08-06 03:31:59 +0200 |
commit | 7df0cc8c37ad0d10adc2181e6c3605049f9566f1 (patch) | |
tree | 8e42afd9a0e3f8c2cd4bcd6921faeb493c61ba88 | |
parent | 3c1040007a354ce55bd964beabac94b67c1f6fc7 (diff) |
Using shared_ptrs to properly delete our LuaExecFile in all cases.
-rw-r--r-- | src/LuaLoad.cc | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/LuaLoad.cc b/src/LuaLoad.cc index de7501f..a2f12ea 100644 --- a/src/LuaLoad.cc +++ b/src/LuaLoad.cc @@ -1,3 +1,5 @@ +#include <memory> + #include "LuaLoad.h" #include "LuaTask.h" #include "Buffer.h" @@ -37,19 +39,17 @@ struct sLua_LuaLoad { h = new Input(L.tostring()); status = OPENING; } - LuaExecFile * execFile = NULL; + std::shared_ptr<LuaExecFile> execFile(new LuaExecFile(h)); return L.yield(Future<int>([L, status, h, execFile]() mutable { switch (status) { case OPENING: h.asA<Input>()->open(); status = CREATETASK; case CREATETASK: - execFile = new LuaExecFile(h); status = WAITTASK; execFile->exec(L); case WAITTASK: - execFile->throwError(); // will induce a memory leak in case of an actual error. - delete execFile; + execFile->throwError(); } return 0; })); |