I think i have a bug with the function ImageToBlob because it takes a large amount of memory.
Here is my code :
Code: Select all
void modify_img(t_list *params, t_final_img *output)
{
size_t size;
unsigned char *blob;
MagickPixelPacket background;
ImageInfo *image_info;
ExceptionInfo *exception;
background.red = 0;
background.blue = 0;
background.green = 0;
background.opacity = 0;
size = 0;
image_info = AcquireImageInfo();
exception = AcquireExceptionInfo();
strcpy(image_info->filename, "dummy.");
strcat(image_info->filename, output->extend);
image_info->quality = output->quality;
output->image = NewMagickImage(image_info, 512, 512, &background);
calc_pixel(params, output);
write_header_http(output);
blob = ImageToBlob(image_info, output->image, &size, exception);
if (exception->severity != UndefinedException)
CatchException(exception);
fwrite(blob, size, 1, stdout);
fflush(stdout);
if (cache_activated)
writeInCache(blob, output, size);
blob = xfree(blob);
DestroyImageInfo(image_info);
DestroyExceptionInfo(exception);
DestroyImage(output->image);
}
Strace :
The second param of the 2 big mmap change every time I restart the program.munmap(0xb6033000, 2101248) = 0
mmap2(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6213000
mmap2(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb61f2000
mmap2(NULL, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb61d1000
mmap2(NULL, 834367488, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x8427b000
mmap2(NULL, 834367488, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x526c4000
mremap(0xb6213000, 135168, 430080, MREMAP_MAYMOVE) = 0xb6168000
munmap(0x8427b000, 834367488) = 0
My function calc_pixel is just copying an image into output->image. write_header_http is writing a content-type in stdout.$ MagickCore-config --version
6.6.2 Q16
Did I make some mistake or is it a bug ?
Thanks for help.