possible memory leak in MagickReadImage (version 6.6.9-3)

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
hawk
Posts: 2
Joined: 2011-04-04T02:39:28-07:00
Authentication code: 8675308

possible memory leak in MagickReadImage (version 6.6.9-3)

Post by hawk »

Hello,

I have made a simple function to resize a jpeg image :

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include <wand/magick_wand.h>

static pthread_mutex_t mutex_im = PTHREAD_MUTEX_INITIALIZER;

int resizeimage(void)
{
        int ret=0; 
        float factor = 0.5;
        int height, width;
        MagickBooleanType
        status;
        MagickWand
        *magick_wand;

        pthread_mutex_lock(&mutex_im);

        MagickWandGenesis();
        magick_wand = NewMagickWand();
        status = MagickReadImage(magick_wand, "image.jpg");

        if (status == MagickFalse)
        {   
                ret = -1; 
                printf("Impossible de lire image.jpg\n");
                goto end;
        }   

        width = MagickGetImageWidth(magick_wand) * factor;
        height = MagickGetImageHeight(magick_wand) * factor;
        MagickResizeImage(magick_wand, width, height, LanczosFilter, 1.0);
        status = MagickWriteImages(magick_wand, "image2.jpg", 0); 

        if (status == MagickFalse)
        {   
                ret = -1; 
                printf("Impossible d'ecrire image2.gif\n");
                goto end;
        }   

end:
        magick_wand = DestroyMagickWand(magick_wand);
        MagickWandTerminus();
        pthread_mutex_unlock(&mutex_im);
        return ret;
}

int main(void)
{
        resizeimage();
        return 0;
}
when I lauch valgrind I have memory leak :
  • valgrind --leak-check=full test_resizeimage

    ==8701== Memcheck, a memory error detector
    ==8701== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
    ==8701== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
    ==8701== Command: test_resizeimage
    ==8701==
    ==8701==
    ==8701== HEAP SUMMARY:
    ==8701== in use at exit: 49,376 bytes in 1,329 blocks
    ==8701== total heap usage: 1,654 allocs, 325 frees, 728,485 bytes allocated
    ==8701==
    ==8701== 117 (84 direct, 33 indirect) bytes in 1 blocks are definitely lost in loss record 1,105 of 1,112
    ==8701== at 0x4023BE8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
    ==8701== by 0x4211405: AcquireMagickMemory (in /usr/lib/libMagickCore.so.4.0.1)
    ==8701== by 0x420FC5C: SetMagickInfo (in /usr/lib/libMagickCore.so.4.0.1)
    ==8701== by 0x42DA553: RegisterMAGICKImage (in /usr/lib/libMagickCore.so.4.0.1)
    ==8701== by 0x427F86E: RegisterStaticModules (in /usr/lib/libMagickCore.so.4.0.1)
    ==8701== by 0x420FFE0: GetMagickInfo (in /usr/lib/libMagickCore.so.4.0.1)
    ==8701== by 0x4200F62: SetImageInfo (in /usr/lib/libMagickCore.so.4.0.1)
    ==8701== by 0x4187D80: ReadImage (in /usr/lib/libMagickCore.so.4.0.1)
    ==8701== by 0x40AB6D2: MagickReadImage (in /usr/lib/libMagickWand.so.4.0.1)
    ==8701== by 0x8048818: resizeimage (resizeimage.c:24)
    ==8701== by 0x468BDA5: (below main) (in /lib/libc-2.13.so)
    ==8701==
    ==8701== LEAK SUMMARY:
    ==8701== definitely lost: 84 bytes in 1 blocks
    ==8701== indirectly lost: 33 bytes in 3 blocks
    ==8701== possibly lost: 0 bytes in 0 blocks
    ==8701== still reachable: 49,259 bytes in 1,325 blocks
    ==8701== suppressed: 0 bytes in 0 blocks
    ==8701== Reachable blocks (those to which a pointer was found) are not shown.
    ==8701== To see them, rerun with: --leak-check=full --show-reachable=yes
    ==8701==
    ==8701== For counts of detected and suppressed errors, rerun with: -v
    ==8701== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 43 from 8)
Regards,

Thomas
hawk
Posts: 2
Joined: 2011-04-04T02:39:28-07:00
Authentication code: 8675308

Re: possible memory leak in MagickReadImage (version 6.6.9-3

Post by hawk »

Sorry my apps was linked with imagemagick 6.6.8-5

No more problem with 6.6.9-3
Post Reply