From ff75b2df51e8732e85b9f71167aa42b63de07e98 Mon Sep 17 00:00:00 2001 From: Leon Klingele Date: Tue, 21 Aug 2018 10:55:39 +0200 Subject: [PATCH] go: Call 'heif_context_read_from_memory_without_copy' instead of deprecated function heif.c:319 says: // DEPRECATED: use heif_context_read_from_memory_without_copy() instead. --- go/heif/heif.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/go/heif/heif.go b/go/heif/heif.go index f2884b1b6a..727c983686 100644 --- a/go/heif/heif.go +++ b/go/heif/heif.go @@ -321,7 +321,12 @@ func (c *Context) ReadFromFile(filename string) error { func (c *Context) ReadFromMemory(data []byte) error { // TODO: Use reader API internally. - err := C.heif_context_read_from_memory(c.context, unsafe.Pointer(&data[0]), C.size_t(len(data)), nil) + cData := C.CBytes(data) + runtime.SetFinalizer(&cData, func(p *unsafe.Pointer) { + C.free(*p) + runtime.SetFinalizer(cData, nil) + }) + err := C.heif_context_read_from_memory_without_copy(c.context, cData, C.size_t(len(data)), nil) return convertHeifError(err) }