From 28d5b2dbde405cff22ccbbc936c5585ba58c47bb Mon Sep 17 00:00:00 2001 From: Pedro Mendez Date: Wed, 29 May 2019 15:59:54 +0200 Subject: [PATCH] GM-1: get pointer to private data and check if it is not nil, if that is the case set to nil, in order to avoid warning on sendmail engine.c mi_clr_ctx(ctx) function --- gomilter.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gomilter.go b/gomilter.go index 68e0d2d..1a32958 100644 --- a/gomilter.go +++ b/gomilter.go @@ -343,6 +343,19 @@ func Go_xxfi_close(ctx *C.SMFICTX) C.sfsistat { if milter.GetDebug() { logger.Printf("Close callback returned: %d\n", code) } + + // Verify if the private data from ctx is already NULL + // Call libmilter smfi_getpriv to get a pointer to our data + CArray := (*byte)(C.smfi_getpriv(ctx)) + pointerToData := unsafe.Pointer(CArray) + if pointerToData != nil { + lenStart := uintptr(unsafe.Pointer(CArray)) + // Free the data malloc'ed by C + C.free(unsafe.Pointer(lenStart)) + C.smfi_setpriv(ctx, nil) + } + + return C.sfsistat(code) }