mirror of https://gitlab.com/nakst/essence
script console: deallocate memory after running script
This commit is contained in:
parent
27b2c00b97
commit
b809edf13b
|
@ -2,8 +2,6 @@
|
||||||
#include <essence.h>
|
#include <essence.h>
|
||||||
#include <shared/array.cpp>
|
#include <shared/array.cpp>
|
||||||
|
|
||||||
// TODO Check for heap allocation leaks.
|
|
||||||
|
|
||||||
struct Instance : EsInstance {
|
struct Instance : EsInstance {
|
||||||
EsCommand commandClearOutput;
|
EsCommand commandClearOutput;
|
||||||
|
|
||||||
|
@ -622,15 +620,19 @@ void AddREPLResult(ExecutionContext *context, EsElement *parent, Node *type, Val
|
||||||
if (type->type == T_INT) {
|
if (type->type == T_INT) {
|
||||||
char *buffer = EsStringAllocateAndFormat(&bytes, "%d", value.i);
|
char *buffer = EsStringAllocateAndFormat(&bytes, "%d", value.i);
|
||||||
EsTextDisplayCreate(parent, ES_CELL_H_FILL, &styleOutputData, buffer, bytes);
|
EsTextDisplayCreate(parent, ES_CELL_H_FILL, &styleOutputData, buffer, bytes);
|
||||||
|
EsHeapFree(buffer);
|
||||||
} else if (type->type == T_BOOL) {
|
} else if (type->type == T_BOOL) {
|
||||||
char *buffer = EsStringAllocateAndFormat(&bytes, "%z", value.i ? "true" : "false");
|
char *buffer = EsStringAllocateAndFormat(&bytes, "%z", value.i ? "true" : "false");
|
||||||
EsTextDisplayCreate(parent, ES_CELL_H_FILL, &styleOutputData, buffer, bytes);
|
EsTextDisplayCreate(parent, ES_CELL_H_FILL, &styleOutputData, buffer, bytes);
|
||||||
|
EsHeapFree(buffer);
|
||||||
} else if (type->type == T_NULL) {
|
} else if (type->type == T_NULL) {
|
||||||
char *buffer = EsStringAllocateAndFormat(&bytes, "%z", "null");
|
char *buffer = EsStringAllocateAndFormat(&bytes, "%z", "null");
|
||||||
EsTextDisplayCreate(parent, ES_CELL_H_FILL, &styleOutputData, buffer, bytes);
|
EsTextDisplayCreate(parent, ES_CELL_H_FILL, &styleOutputData, buffer, bytes);
|
||||||
|
EsHeapFree(buffer);
|
||||||
} else if (type->type == T_FLOAT) {
|
} else if (type->type == T_FLOAT) {
|
||||||
char *buffer = EsStringAllocateAndFormat(&bytes, "%F", value.f);
|
char *buffer = EsStringAllocateAndFormat(&bytes, "%F", value.f);
|
||||||
EsTextDisplayCreate(parent, ES_CELL_H_FILL, &styleOutputData, buffer, bytes);
|
EsTextDisplayCreate(parent, ES_CELL_H_FILL, &styleOutputData, buffer, bytes);
|
||||||
|
EsHeapFree(buffer);
|
||||||
} else if (type->type == T_STR) {
|
} else if (type->type == T_STR) {
|
||||||
EsAssert(context->heapEntriesAllocated > (uint64_t) value.i);
|
EsAssert(context->heapEntriesAllocated > (uint64_t) value.i);
|
||||||
HeapEntry *entry = &context->heap[value.i];
|
HeapEntry *entry = &context->heap[value.i];
|
||||||
|
@ -757,6 +759,16 @@ void ScriptThread(EsGeneric _instance) {
|
||||||
AddOutput(instance, EsLiteral("\n"));
|
AddOutput(instance, EsLiteral("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (fixedAllocationBlocks) {
|
||||||
|
void *block = fixedAllocationBlocks;
|
||||||
|
fixedAllocationBlocks = (void **) *fixedAllocationBlocks;
|
||||||
|
EsHeapFree(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
fixedAllocationCurrentBlock = nullptr;
|
||||||
|
fixedAllocationCurrentPosition = 0;
|
||||||
|
fixedAllocationCurrentSize = 0;
|
||||||
|
|
||||||
EsMessageMutexAcquire();
|
EsMessageMutexAcquire();
|
||||||
|
|
||||||
if (!instance->anyOutput) {
|
if (!instance->anyOutput) {
|
||||||
|
|
|
@ -933,6 +933,7 @@ EsMessage *EsMessageReceive() {
|
||||||
EsAssert(!api.workQueue.Length());
|
EsAssert(!api.workQueue.Length());
|
||||||
api.workThreads.Free();
|
api.workThreads.Free();
|
||||||
api.workQueue.Free();
|
api.workQueue.Free();
|
||||||
|
api.connectedDevices.Free();
|
||||||
#ifdef ENABLE_POSIX_SUBSYSTEM
|
#ifdef ENABLE_POSIX_SUBSYSTEM
|
||||||
POSIXCleanup();
|
POSIXCleanup();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -691,6 +691,8 @@ bool EsFontDatabaseLookupByID(EsFontFamily id, EsFontInformation *information) {
|
||||||
}
|
}
|
||||||
|
|
||||||
EsFontFamily EsFontDatabaseInsertFile(const EsFontInformation *information, EsFileStore *store) {
|
EsFontFamily EsFontDatabaseInsertFile(const EsFontInformation *information, EsFileStore *store) {
|
||||||
|
// TODO Locking.
|
||||||
|
|
||||||
FontInitialise();
|
FontInitialise();
|
||||||
EsAssert(store->handles);
|
EsAssert(store->handles);
|
||||||
FontDatabaseEntry *entry = nullptr;
|
FontDatabaseEntry *entry = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue