Skip to content

Commit

Permalink
Add extra error check to GetImageBlob and GetImagesBlob before freein…
Browse files Browse the repository at this point in the history
…g memory (refs #329)
  • Loading branch information
justinfx committed Dec 16, 2024
1 parent c974483 commit e0231e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module gopkg.in/gographics/imagick.v3

go 1.13
go 1.22
6 changes: 6 additions & 0 deletions imagick/magick_wand_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,9 @@ func (mw *MagickWand) GetImageBackgroundColor() (bgColor *PixelWand, err error)
func (mw *MagickWand) GetImageBlob() ([]byte, error) {
clen := C.size_t(0)
csblob := C.MagickGetImageBlob(mw.mw, &clen)
if err := mw.GetLastError(); csblob == nil && err != nil {
return nil, err
}
defer relinquishMemory(unsafe.Pointer(csblob))
ret := C.GoBytes(unsafe.Pointer(csblob), C.int(clen))
runtime.KeepAlive(mw)
Expand All @@ -958,6 +961,9 @@ func (mw *MagickWand) GetImageBlob() ([]byte, error) {
func (mw *MagickWand) GetImagesBlob() ([]byte, error) {
clen := C.size_t(0)
csblob := C.MagickGetImagesBlob(mw.mw, &clen)
if err := mw.GetLastError(); csblob == nil && err != nil {
return nil, err
}
defer relinquishMemory(unsafe.Pointer(csblob))
ret := C.GoBytes(unsafe.Pointer(csblob), C.int(clen))
runtime.KeepAlive(mw)
Expand Down

0 comments on commit e0231e9

Please sign in to comment.