From 9f90e14b9eea6d1aedc3c1e2661f42add05a4541 Mon Sep 17 00:00:00 2001 From: Larry Frieson Date: Thu, 11 Apr 2024 13:16:48 -0700 Subject: [PATCH] Fix extsample to cleanup all memory used for cnex CI heap debug testing --- lib/extsample/extsample.c | 16 ++++++++++++++-- lib/extsample/extsample.neon | 2 ++ lib/extsample/t/extsample-test.neon | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/extsample/extsample.c b/lib/extsample/extsample.c index db03b42ba..28a3cfdcf 100644 --- a/lib/extsample/extsample.c +++ b/lib/extsample/extsample.c @@ -1,7 +1,11 @@ +#include #include +#include + #include "neonext.h" +const char *neon = "Neon!"; const struct Ne_MethodTable *Ne; struct Ne_Cell *g_cb; @@ -161,14 +165,22 @@ Ne_EXPORT int Ne_raiseException(struct Ne_Cell *retval, struct Ne_ParameterList Ne_EXPORT int Ne_allocHandle(struct Ne_Cell *retval, struct Ne_ParameterList *in_params, struct Ne_ParameterList *out_params) { - void *p = malloc(1); + void *p = malloc(sizeof(neon)); + memcpy(p, neon, sizeof(neon)); Ne->cell_set_pointer(retval, p); return Ne_SUCCESS; } Ne_EXPORT int Ne_freeHandle(struct Ne_Cell *retval, struct Ne_ParameterList *in_params, struct Ne_ParameterList *out_params) { - void *p = Ne->cell_get_pointer(Ne->parameterlist_get_cell(in_params, 0)); + char *p = Ne->cell_get_pointer(Ne->parameterlist_get_cell(in_params, 0)); + assert(memcmp(p, neon, sizeof(neon)) == 0); free(p); return Ne_SUCCESS; } + +Ne_EXPORT int Ne_shutdownExtension(struct Ne_Cell *retval, struct Ne_ParameterList *in_params, struct Ne_ParameterList *out_params) +{ + Ne->cell_free(g_cb); + return Ne_SUCCESS; +} diff --git a/lib/extsample/extsample.neon b/lib/extsample/extsample.neon index 217532a55..de23dc124 100644 --- a/lib/extsample/extsample.neon +++ b/lib/extsample/extsample.neon @@ -46,3 +46,5 @@ EXPORT DECLARE EXTENSION FUNCTION raiseException() EXPORT DECLARE EXTENSION FUNCTION allocHandle(): Handle EXPORT DECLARE EXTENSION FUNCTION freeHandle(h: Handle) + +EXPORT DECLARE EXTENSION FUNCTION shutdownExtension() diff --git a/lib/extsample/t/extsample-test.neon b/lib/extsample/t/extsample-test.neon index dc7699635..3ca44915c 100644 --- a/lib/extsample/t/extsample-test.neon +++ b/lib/extsample/t/extsample-test.neon @@ -53,3 +53,5 @@ END TRY LET h: extsample.Handle := extsample.allocHandle() TESTCASE h <> NIL extsample.freeHandle(h) + +extsample.shutdownExtension()