Page 1 of 1

Memory leak in DestroyKernelInfo?

Posted: 2010-08-31T01:29:25-07:00
by jcsm
Hello

I have this problem on v6.6.1 (Windows VS 9.0.30729.1 SP), the "destructor" function allocates memory before releasing for "values", without releasing if it previously had been reserved.

Original code:

Code: Select all

MagickExport KernelInfo *DestroyKernelInfo(KernelInfo *kernel)
{
  assert(kernel != (KernelInfo *) NULL);

  kernel->values=(double *) AcquireQuantumMemory(kernel->width,
                              kernel->height*sizeof(double));
  kernel->values=(double *)RelinquishMagickMemory(kernel->values);
  kernel=(KernelInfo *) RelinquishMagickMemory(kernel);
  return(kernel);
}
modified code (without memory leak):

Code: Select all

MagickExport KernelInfo *DestroyKernelInfo(KernelInfo *kernel)
{
  assert(kernel != (KernelInfo *) NULL);

  kernel->values=(double *)RelinquishMagickMemory(kernel->values);
  kernel=(KernelInfo *) RelinquishMagickMemory(kernel);
  return(kernel);
}
I have recently begun to use this library, could someone confirm that this solution is 100% safe?

Thank you
jcs

Re: Memory leak in DestroyKernelInfo?

Posted: 2010-08-31T05:12:08-07:00
by magick
The bug you encountered was transient. Its fixed in the current release of ImageMagick, 6.6.3. The method now looks like this:

Code: Select all

MagickExport KernelInfo *DestroyKernelInfo(KernelInfo *kernel)
{
  assert(kernel != (KernelInfo *) NULL);

  if ( kernel->next != (KernelInfo *) NULL )
    kernel->next = DestroyKernelInfo(kernel->next);

  kernel->values = (double *)RelinquishMagickMemory(kernel->values);
  kernel = (KernelInfo *) RelinquishMagickMemory(kernel);
  return(kernel);
}

Re: Memory leak in DestroyKernelInfo?

Posted: 2010-08-31T05:22:32-07:00
by jcsm
I'm sorry,next time I will see the latest version before asking.
Thank you
jcs

Re: Memory leak in DestroyKernelInfo?

Posted: 2010-08-31T18:35:35-07:00
by anthony
The previous bug was probably my bad, during the development of Morphology.

The new version is recursive, so as to correctly destroy a multi-kernel list which is requires by the second morphology implementation phase whcih required applying morphology operators against multiple kernels. Specifically HitAndMiss (HMT), Thin, Thick.

At the same time methods of specifying one kernel then generating a list of rotated versions were also added. See IM examples, Morphology, Multi-Kernel List Handling
http://www.imagemagick.org/Usage/morpho ... lti-kernel

At this time this is the primary source of morphology information. I have not yet written a reference summery for the official command line options page. Though others are welcome to give an initial summery.

Morphology is not finished either. I have many things on my ToDo for it.

Code: Select all

    * Morphology / Convolve
    + Add faster 2-pass Distance method
    + Add +morphology for higher level methods, and default kernel selection
    + Rotation of any 1-d kernel by given angle  (angled linear blurs)
    + Read Kernel Definitions from a text file  '@filename'
    + Kernel from small imager(s)    '@image'  ???
    + More kernels...
        - hexagonal shaped kernel
        - octogonal shaped kernel
        - line of given length and angle
        - Calculated Larger sized Angled Deritive Kernels
        - Inverse Square falloff  convolution kernels
        - Expotental falloff convolution kernels.
        - add 'filter' and 'filter2d' convolution kernels
    + More Morphology methods...
        - True GreyScale Morphology (not simply flat kernel)
        - Feather  (Like Distance but anti-aliased shape handling)
        - Conditional Dilate  (a masked multi-point flood fill)
        - Final Erode   (Peaks in Distance Method)
        - Voronoi - Color spread from a given mask of selected pixels
        - Diffusion - Blurred color spread from a given mask of pixels
        - Distance (MAT) Skeletion Determination (how?)
    + Replace -convolve, -gaussian, -blur, -sharpen etc to use the
      new morphology funtions.  Also fixs '-bias' bug in these.
      Make automatic normalization the default?
    + Also look at  -edge and -shade, as these probably use convolve too.

  * Image Segmentation
      + Morphology Component Labeling (diamond/square neighbourhoods)
      + Orthogonal segmentation (vertial/horizontal separation)
          - mid-gap divisions
          - separate gap images
          - no gap images
          - recursive option
I have no idea when I will next get time to work on or implement ANY of the above.