From f5dd7f7ed3f9924a1271b5e2810ee00a5a756f44 Mon Sep 17 00:00:00 2001 From: Isamu Mogi Date: Wed, 15 Mar 2017 16:24:17 +0900 Subject: [PATCH] Avoid false pointer deallocation in Go 1.8 See https://github.com/golang/go/issues/19135#issuecomment-280560041 --- webp/encode.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/webp/encode.go b/webp/encode.go index 4cfbfcf..de0484a 100644 --- a/webp/encode.go +++ b/webp/encode.go @@ -7,8 +7,8 @@ package webp int writeWebP(uint8_t*, size_t, struct WebPPicture*); -static WebPPicture *malloc_WebPPicture(void) { - return malloc(sizeof(WebPPicture)); +static WebPPicture *calloc_WebPPicture(void) { + return calloc(sizeof(WebPPicture), 1); } static void free_WebPPicture(WebPPicture* webpPicture) { @@ -445,7 +445,7 @@ func EncodeRGBA(w io.Writer, img image.Image, c *Config) (err error) { return } - pic := C.malloc_WebPPicture() + pic := C.calloc_WebPPicture() if pic == nil { return errors.New("Could not allocate webp picture") } @@ -489,7 +489,7 @@ func EncodeGray(w io.Writer, p *image.Gray, c *Config) (err error) { return } - pic := C.malloc_WebPPicture() + pic := C.calloc_WebPPicture() if pic == nil { return errors.New("Could not allocate webp picture") } @@ -524,7 +524,7 @@ func EncodeYUVA(w io.Writer, img *YUVAImage, c *Config) (err error) { return } - pic := C.malloc_WebPPicture() + pic := C.calloc_WebPPicture() if pic == nil { return errors.New("Could not allocate webp picture") }