added frees for malloced data, except for NScript::Node, todo: add frees also for Node

This commit is contained in:
christallo 2022-07-21 02:52:27 +02:00
parent 1ab1a961b2
commit bb8b8f49a9
3 changed files with 16 additions and 1 deletions

View File

@ -144,7 +144,10 @@ void NDSConsole::returnPrompt()
// removing the old prompt buffer whether it's empty (returnPrompt worked because promptBuffer was set to another recent prompt)
if (recentPrompts[recentPrompts.size() - 1]->empty())
{
delete recentPrompts[recentPrompts.size() - 1];
recentPrompts.pop_back();
}
// reprinting the current prompt buffer without the cursor
flushPromptBuffer(1, false);

View File

@ -39,6 +39,12 @@ class NDSConsole
keyboardShow();
}
public: ~NDSConsole()
{
for (const auto& prompt : recentPrompts)
delete prompt;
}
public: void processVirtualKey(int key);
public: void insertChar(char c);

View File

@ -318,7 +318,13 @@ NScript::Node NScript::Evaluator::evaluateCallProcess(CallNode call, Position po
processArgv[call.args.size()] = (char*)nullptr;
return Node(NodeKind::Num, (NodeValue) { .num = float64(execv(processPath, processArgv)) }, pos);
auto result = Node(NodeKind::Num, (NodeValue) { .num = float64(execv(processPath, processArgv)) }, pos);
// freeing all args including processPath, which is the first arg
for (uint64_t i = 0; i < call.args.size(); i++)
delete [] processArgv[i];
return ;
}
NScript::Node NScript::Evaluator::evaluateCall(CallNode call, Position pos)