WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit e0231e9

Browse files
committed
Add extra error check to GetImageBlob and GetImagesBlob before freeing memory (refs #329)
1 parent c974483 commit e0231e9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module gopkg.in/gographics/imagick.v3
22

3-
go 1.13
3+
go 1.22

imagick/magick_wand_image.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,9 @@ func (mw *MagickWand) GetImageBackgroundColor() (bgColor *PixelWand, err error)
940940
func (mw *MagickWand) GetImageBlob() ([]byte, error) {
941941
clen := C.size_t(0)
942942
csblob := C.MagickGetImageBlob(mw.mw, &clen)
943+
if err := mw.GetLastError(); csblob == nil && err != nil {
944+
return nil, err
945+
}
943946
defer relinquishMemory(unsafe.Pointer(csblob))
944947
ret := C.GoBytes(unsafe.Pointer(csblob), C.int(clen))
945948
runtime.KeepAlive(mw)
@@ -958,6 +961,9 @@ func (mw *MagickWand) GetImageBlob() ([]byte, error) {
958961
func (mw *MagickWand) GetImagesBlob() ([]byte, error) {
959962
clen := C.size_t(0)
960963
csblob := C.MagickGetImagesBlob(mw.mw, &clen)
964+
if err := mw.GetLastError(); csblob == nil && err != nil {
965+
return nil, err
966+
}
961967
defer relinquishMemory(unsafe.Pointer(csblob))
962968
ret := C.GoBytes(unsafe.Pointer(csblob), C.int(clen))
963969
runtime.KeepAlive(mw)

0 commit comments

Comments
 (0)