From ff2bbca1ab71bed291ffb44da498969f4b1a2cf2 Mon Sep 17 00:00:00 2001 From: Slapparoo Date: Mon, 19 Dec 2022 22:32:49 +1300 Subject: [PATCH 1/2] Convenience method FreeAll --- src/Kernel/KernelC.HH | 3 ++- src/Kernel/Memory/MAllocFree.ZC | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Kernel/KernelC.HH b/src/Kernel/KernelC.HH index 9bd4886a..8fba36fa 100755 --- a/src/Kernel/KernelC.HH +++ b/src/Kernel/KernelC.HH @@ -555,6 +555,7 @@ public extern U8 *ReAlloc( U8 *src, U64 size, CTask *mem_task=NU public _extern _MHEAP_CTRL CHeapCtrl *MHeapCtrl( U8 *src); public _extern _MSIZE I64 MSize( U8 *src); //size of heap object public _extern _MSIZE2 I64 MSize2( U8 *src); //Internal size +public extern U0 FreeAll(...); //Free all pointers passed #help_index "Memory/HeapCtrl" public extern U0 HeapCtrlDel( CHeapCtrl *hc); @@ -735,4 +736,4 @@ public extern F64 tS(); //From SysTimerFreq. #help_index "Windows" public extern Bool WinInside(I64 x, I64 y, CTask *task=NULL, I64 border=0); -#help_index "" \ No newline at end of file +#help_index "" diff --git a/src/Kernel/Memory/MAllocFree.ZC b/src/Kernel/Memory/MAllocFree.ZC index 92912b7d..969b9567 100755 --- a/src/Kernel/Memory/MAllocFree.ZC +++ b/src/Kernel/Memory/MAllocFree.ZC @@ -504,3 +504,10 @@ U8 *SysStrNew(U8 *buf) {//Alloc copy of string in System task's heap. return StrNew(buf, sys_task); } + +U0 FreeAll(...) +{// Free all pointers passed + U64 cur_arg = 0; + while (argc--) + Free(argv[cur_arg++]); +} From 6d6c059f38784b5aa8655ed27275bbc58d94fa50 Mon Sep 17 00:00:00 2001 From: TomAwezome Date: Wed, 21 Dec 2022 03:33:23 -0500 Subject: [PATCH 2/2] Fix FreeAll PR formatting. --- src/Kernel/KernelC.HH | 2 +- src/Kernel/Memory/MAllocFree.ZC | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Kernel/KernelC.HH b/src/Kernel/KernelC.HH index 8fba36fa..f050d7ee 100755 --- a/src/Kernel/KernelC.HH +++ b/src/Kernel/KernelC.HH @@ -555,7 +555,7 @@ public extern U8 *ReAlloc( U8 *src, U64 size, CTask *mem_task=NU public _extern _MHEAP_CTRL CHeapCtrl *MHeapCtrl( U8 *src); public _extern _MSIZE I64 MSize( U8 *src); //size of heap object public _extern _MSIZE2 I64 MSize2( U8 *src); //Internal size -public extern U0 FreeAll(...); //Free all pointers passed +public extern U0 FreeAll(...); //Free all pointers passed #help_index "Memory/HeapCtrl" public extern U0 HeapCtrlDel( CHeapCtrl *hc); diff --git a/src/Kernel/Memory/MAllocFree.ZC b/src/Kernel/Memory/MAllocFree.ZC index 969b9567..a72c0565 100755 --- a/src/Kernel/Memory/MAllocFree.ZC +++ b/src/Kernel/Memory/MAllocFree.ZC @@ -508,6 +508,7 @@ U8 *SysStrNew(U8 *buf) U0 FreeAll(...) {// Free all pointers passed U64 cur_arg = 0; + while (argc--) Free(argv[cur_arg++]); }