Skip to content

Commit

Permalink
Fix dereferencing / free memory issues with GetImageHistogram (#147)
Browse files Browse the repository at this point in the history
Fix crash when destroying *C.PixelWand via GetImageHistogram;
Fix crash when wrongly assuming num colors in GetImageHistogram;
  • Loading branch information
ryaka authored and justinfx committed Jan 10, 2018
1 parent 48240be commit e5c95c3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions imagick/magick_wand_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -1085,20 +1085,20 @@ func (mw *MagickWand) GetImageHeight() uint {
//
// numberColors: the number of unique colors in the image and the number of
// pixel wands returned.
func (mw *MagickWand) GetImageHistogram() (numberColors uint, pws []PixelWand) {
func (mw *MagickWand) GetImageHistogram() (numberColors uint, pws []*PixelWand) {
cnc := C.size_t(0)
p := C.MagickGetImageHistogram(mw.mw, &cnc)
defer relinquishMemory(unsafe.Pointer(p))
q := uintptr(unsafe.Pointer(p))
for {
numberColors = uint(cnc)
for i := 0; i < int(numberColors); i++ {
p = (**C.PixelWand)(unsafe.Pointer(q))
if *p == nil {
break
}
pws = append(pws, *newPixelWand(*p))
pws = append(pws, newPixelWand(*p))
q += unsafe.Sizeof(q)
}
numberColors = uint(cnc)
runtime.KeepAlive(mw)
return
}
Expand Down

0 comments on commit e5c95c3

Please sign in to comment.