Page 1 of 1

Memory Leak while handle psd file

Posted: 2015-12-07T17:54:17-07:00
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

Re: Memory Leak while handle psd file

Posted: 2015-12-15T03:42:11-07:00
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.

Re: Memory Leak while handle psd file

Posted: 2015-12-16T02:03:12-07:00
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()
    }
  }
}

Re: Memory Leak while handle psd file

Posted: 2015-12-16T13:36:10-07:00
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.

Re: Memory Leak while handle psd file

Posted: 2015-12-16T20:37:10-07:00
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.

Re: Memory Leak while handle psd file

Posted: 2015-12-16T23:25:15-07:00
by dlemstra
Could you check if https://github.com/ImageMagick/ImageMag ... 2cad1f84a4 resolves your issue?

Re: Memory Leak while handle psd file

Posted: 2015-12-17T07:25:37-07:00
by kayaklee
Sorry, memory still leak

Re: Memory Leak while handle psd file

Posted: 2015-12-17T07:56:50-07:00
by dlemstra
No problem that was just a quick thing I noticed this morning. Will do a proper check tomorrow night.

Re: Memory Leak while handle psd file

Posted: 2015-12-18T13:50:24-07:00
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.

Re: Memory Leak while handle psd file

Posted: 2015-12-18T17:55:02-07:00
by kayaklee
Yes, it works

Thanks!