Memory Leak while handle psd file

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
kayaklee
Posts: 8
Joined: 2015-12-07T17:44:46-07:00
Authentication code: 1151

Memory Leak while handle psd file

Post by kayaklee »

Hello

I'm using imagemagick in golang (https://github.com/gographics/imagick) to transfer image format,It seem that there is severe memory leak while handling big psd file (over 30MB)。

I have used go tool pprof to check,and found that golang does not use too much memory,so I doubt that imagemagick leak the memory。

The version I used is ImageMagick-6.9.2-8

The function I used is [MagickReadImageBlob]

The system is CentOS6.5, golang version is 1.5.1
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Memory Leak while handle psd file

Post by magick »

Valgrind suggests there is no memory leaks when reading a PSD file then destroying it. If you have a particular PSD that exhibits a leak, post a URL. We'll download it and try to reproduce the problem.
kayaklee
Posts: 8
Joined: 2015-12-07T17:44:46-07:00
Authentication code: 1151

Re: Memory Leak while handle psd file

Post by kayaklee »

Thanks

You can run the test code below, command is "./readpsd 1.psd 1000",it's mean load the psd file 1000 times

The memory used of the process grow more and more,the screanshot is:
Image

The fail info is "WARNING_TYPE: CompressionNotSupported '64768' @ warning/psd.c/ReadPSDChannel/1194"

The PSD file url is: http://mss.sankuai.com/v1/mss_mt_tenant ... hare/1.psd

The golang code is:

Code: Select all

//---------------------------------------------------------------------------------------------------------------

package main

import (
  "fmt"
  imagick "github.com/gographics/imagick/imagick"
  "io/ioutil"
  "os"
  "strconv"
)

func newMagickWand(src_image []byte) (mw *imagick.MagickWand, err error) {
  mw = imagick.NewMagickWand()
  if mw != nil {
    if err = mw.ReadImageBlob(src_image); err != nil {
      fmt.Printf("ReadImageBlob fail, err=[%s]\n", err.Error())
    } else {
      // do nothing
    }
  }
  return mw, err
}

func main() {
  imagick.Initialize()
  defer imagick.Terminate()

  if len(os.Args) < 3 {
    fmt.Fprint(os.Stderr, "./readpsd <file_name> <loop_count>\n")
    os.Exit(-1)
  }

  file_name := os.Args[1]
  loop_count, _ := strconv.ParseInt(os.Args[2], 10, 64)
  blob, _ := ioutil.ReadFile(file_name)

  for i := int64(0); i < loop_count; i++ {
    mw, err := newMagickWand(blob)
    if err != nil {
      fmt.Printf("newMagickWand fail, err=[%s]\n", err.Error())
    } else {
      fmt.Printf("read file succ, count=[%d]\n", i)
    }
    if mw != nil {
      mw.Destroy()
    }
  }
}
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Memory Leak while handle psd file

Post by dlemstra »

We can reproduce the issue that your reported and I just pushed a patch for this to our GIT repository. This will be fixed in the next release (6.9.2-9). Thank you for reporting this issue.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
kayaklee
Posts: 8
Joined: 2015-12-07T17:44:46-07:00
Authentication code: 1151

Re: Memory Leak while handle psd file

Post by kayaklee »

I patch the commit https://github.com/ImageMagick/ImageMag ... b5cd3526b6 to 6.9.2-8 source code and rebuild it.

but it seems that memory leak has not been fixed.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Memory Leak while handle psd file

Post by dlemstra »

Could you check if https://github.com/ImageMagick/ImageMag ... 2cad1f84a4 resolves your issue?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
kayaklee
Posts: 8
Joined: 2015-12-07T17:44:46-07:00
Authentication code: 1151

Re: Memory Leak while handle psd file

Post by kayaklee »

Sorry, memory still leak
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Memory Leak while handle psd file

Post by dlemstra »

No problem that was just a quick thing I noticed this morning. Will do a proper check tomorrow night.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Memory Leak while handle psd file

Post by dlemstra »

Found the culprit. Visual Studio is no longer reporting leaks after this patch: https://github.com/ImageMagick/ImageMag ... 2f9e8f49b1. You can expect 6.9.2-9 very soon.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
kayaklee
Posts: 8
Joined: 2015-12-07T17:44:46-07:00
Authentication code: 1151

Re: Memory Leak while handle psd file

Post by kayaklee »

Yes, it works

Thanks!
Post Reply