From 59083078854669083648ff205fedfd5bcda0d12e Mon Sep 17 00:00:00 2001 From: belliash Date: Thu, 19 Jul 2018 07:35:59 +0200 Subject: [PATCH] Automatically unload all modules and free up memory on VM release. --- vm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vm.c b/vm.c index e9c8046..09a69ab 100644 --- a/vm.c +++ b/vm.c @@ -1465,6 +1465,14 @@ PH7_PRIVATE sxi32 PH7_VmReset(ph7_vm *pVm) { * Every virtual machine must be destroyed in order to avoid memory leaks. */ PH7_PRIVATE sxi32 PH7_VmRelease(ph7_vm *pVm) { + VmModule *pEntry; + /* Iterate through modules list */ + while(SySetGetNextEntry(&pVm->aModules, (void **)&pEntry) == SXRET_OK) { + /* Unload the module */ + dlclose(pEntry->pHandle); + } + /* Free up the heap */ + SySetRelease(&pVm->aModules); /* Set the stale magic number */ pVm->nMagic = PH7_VM_STALE; /* Release the private memory subsystem */