Bytecode: fix memory leak in Evaluate class
The newly-created FBEGINBLOCK_ and FCALL_ instances were freed using a base-class pointer. But the latter does not have a virtual destructor. Those class instances are now stored by value in containers, so that the destructor of the derived class is used.kalman-mex
parent
9e5bd75611
commit
bd9943a695
|
@ -229,10 +229,10 @@ Evaluate::Evaluate(const filesystem::path &codfile, bool steady_state_arg, const
|
|||
# ifdef DEBUGL
|
||||
mexPrintf("FBEGINBLOCK\n");
|
||||
# endif
|
||||
deserialized_special_instrs.push_back(make_unique<FBEGINBLOCK_>(code));
|
||||
deserialized_fbeginblock.emplace_back(code);
|
||||
begin_block.push_back(instructions_list.size());
|
||||
nb_blocks++;
|
||||
instr = deserialized_special_instrs.back().get();
|
||||
instr = &deserialized_fbeginblock.back();
|
||||
break;
|
||||
case Tags::FJMPIFEVAL:
|
||||
# ifdef DEBUGL
|
||||
|
@ -250,8 +250,8 @@ Evaluate::Evaluate(const filesystem::path &codfile, bool steady_state_arg, const
|
|||
# ifdef DEBUGL
|
||||
mexPrintf("FCALL\n");
|
||||
# endif
|
||||
deserialized_special_instrs.push_back(make_unique<FCALL_>(code));
|
||||
instr = deserialized_special_instrs.back().get();
|
||||
deserialized_fcall.emplace_back(code);
|
||||
instr = &deserialized_fcall.back();
|
||||
break;
|
||||
case Tags::FLDTEF:
|
||||
# ifdef DEBUGL
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <optional>
|
||||
#include <memory>
|
||||
#include <filesystem>
|
||||
#include <deque>
|
||||
|
||||
#include "Bytecode.hh"
|
||||
#include "BasicSymbolTable.hh"
|
||||
|
@ -43,11 +44,15 @@ private:
|
|||
unique_ptr<char[]> raw_bytecode;
|
||||
|
||||
/* Owns read instructions that have their specialized deserializing
|
||||
constructors (and are thus not part of the “code” memory block) */
|
||||
vector<unique_ptr<BytecodeInstruction>> deserialized_special_instrs;
|
||||
constructors (and are thus not part of the “code” memory block). We use
|
||||
std::deque for storing them, because that class guarantees the stability
|
||||
of iterators, and thus of pointers to elements; we store such pointers in
|
||||
the “instructions_list” data member. */
|
||||
deque<FBEGINBLOCK_> deserialized_fbeginblock;
|
||||
deque<FCALL_> deserialized_fcall;
|
||||
|
||||
/* List of deserialized instructions
|
||||
Those are either pointers inside “raw_bytecode” or “deserialized_special_instrs” */
|
||||
Those are either pointers inside “raw_bytecode” or “deserialized_{fbeginblock,fcall}” */
|
||||
instructions_list_t instructions_list;
|
||||
|
||||
// Number of blocks in the model
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 92f42bdf68bbdb217647e5268dc91cc7cf05df87
|
||||
Subproject commit 3a187076859751ebc3f6a4e43c9ffc3149655191
|
Loading…
Reference in New Issue