Commit 01c3051f authored by Paul Eggert's avatar Paul Eggert
Browse files

* image.c (imagemagick_filename_hint): New arg HINT_BUFFER.

Use changed.  This avoids the need to call xmalloc and for the
caller to call xfree, and avoids memory leaks in some situations.
parent 2084152a
2013-08-14 Paul Eggert <eggert@cs.ucla.edu>
* image.c (imagemagick_filename_hint): New arg HINT_BUFFER.
Use changed. This avoids the need to call xmalloc and for the
caller to call xfree, and avoids memory leaks in some situations.
2013-08-14 Dmitry Antipov <dmantipov@yandex.ru> 2013-08-14 Dmitry Antipov <dmantipov@yandex.ru>
* xdisp.c (adjust_window_ends): Move duplicated code to new function. * xdisp.c (adjust_window_ends): Move duplicated code to new function.
......
...@@ -7847,33 +7847,25 @@ imagemagick_error (MagickWand *wand) ...@@ -7847,33 +7847,25 @@ imagemagick_error (MagickWand *wand)
/* Possibly give ImageMagick some extra help to determine the image /* Possibly give ImageMagick some extra help to determine the image
type by supplying a "dummy" filename based on the Content-Type. */ type by supplying a "dummy" filename based on the Content-Type. */
static char* static char *
imagemagick_filename_hint (Lisp_Object spec) imagemagick_filename_hint (Lisp_Object spec, char hint_buffer[MaxTextExtent])
{ {
Lisp_Object format = image_spec_value (spec, intern (":format"), NULL); Lisp_Object symbol = intern ("image-format-suffixes");
Lisp_Object val, symbol = intern ("image-format-suffixes"); Lisp_Object val = find_symbol_value (symbol);
const char *prefix = "/tmp/foo."; Lisp_Object format;
char *name;
if (NILP (Fboundp (symbol)))
return NULL;
val = Fassq (format, Fsymbol_value (symbol));
if (! CONSP (val))
return NULL;
val = Fcdr (val);
if (! CONSP (val)) if (! CONSP (val))
return NULL; return NULL;
val = Fcar (val); format = image_spec_value (spec, intern (":format"), NULL);
val = Fcar_safe (Fcdr_safe (Fassq (format, val)));
if (! STRINGP (val)) if (! STRINGP (val))
return NULL; return NULL;
name = xmalloc (strlen (prefix) + SBYTES (val) + 1); /* It's OK to truncate the hint if it has MaxTextExtent or more bytes,
strcpy (name, prefix); as ImageMagick would ignore the extra bytes anyway. */
strcat (name, SSDATA (val)); snprintf (hint_buffer, MaxTextExtent, "/tmp/foo.%s", SSDATA (val));
return name; return hint_buffer;
} }
/* Helper function for imagemagick_load, which does the actual loading /* Helper function for imagemagick_load, which does the actual loading
...@@ -7909,6 +7901,7 @@ imagemagick_load_image (struct frame *f, struct image *img, ...@@ -7909,6 +7901,7 @@ imagemagick_load_image (struct frame *f, struct image *img,
int desired_width, desired_height; int desired_width, desired_height;
double rotation; double rotation;
int pixelwidth; int pixelwidth;
char hint_buffer[MaxTextExtent];
char *filename_hint = NULL; char *filename_hint = NULL;
/* Handle image index for image types who can contain more than one image. /* Handle image index for image types who can contain more than one image.
...@@ -7923,15 +7916,14 @@ imagemagick_load_image (struct frame *f, struct image *img, ...@@ -7923,15 +7916,14 @@ imagemagick_load_image (struct frame *f, struct image *img,
ping_wand = NewMagickWand (); ping_wand = NewMagickWand ();
/* MagickSetResolution (ping_wand, 2, 2); (Bug#10112) */ /* MagickSetResolution (ping_wand, 2, 2); (Bug#10112) */
if (! filename) if (filename)
filename_hint = imagemagick_filename_hint (img->spec); status = MagickPingImage (ping_wand, filename);
else
if (filename_hint) {
filename_hint = imagemagick_filename_hint (img->spec, hint_buffer);
MagickSetFilename (ping_wand, filename_hint); MagickSetFilename (ping_wand, filename_hint);
status = MagickPingImageBlob (ping_wand, contents, size);
status = filename }
? MagickPingImage (ping_wand, filename)
: MagickPingImageBlob (ping_wand, contents, size);
if (status == MagickFalse) if (status == MagickFalse)
{ {
...@@ -7961,13 +7953,15 @@ imagemagick_load_image (struct frame *f, struct image *img, ...@@ -7961,13 +7953,15 @@ imagemagick_load_image (struct frame *f, struct image *img,
image_wand = NewMagickWand (); image_wand = NewMagickWand ();
if (filename_hint) if (filename)
status = MagickReadImage (image_wand, filename);
else
{
MagickSetFilename (image_wand, filename_hint); MagickSetFilename (image_wand, filename_hint);
status = MagickReadImageBlob (image_wand, contents, size);
}
if ((filename if (status == MagickFalse)
? MagickReadImage (image_wand, filename)
: MagickReadImageBlob (image_wand, contents, size))
== MagickFalse)
{ {
imagemagick_error (image_wand); imagemagick_error (image_wand);
goto imagemagick_error; goto imagemagick_error;
...@@ -8207,16 +8201,11 @@ imagemagick_load_image (struct frame *f, struct image *img, ...@@ -8207,16 +8201,11 @@ imagemagick_load_image (struct frame *f, struct image *img,
/* `MagickWandTerminus' terminates the imagemagick environment. */ /* `MagickWandTerminus' terminates the imagemagick environment. */
MagickWandTerminus (); MagickWandTerminus ();
if (filename_hint)
free (filename_hint);
return 1; return 1;
imagemagick_error: imagemagick_error:
DestroyMagickWand (image_wand); DestroyMagickWand (image_wand);
if (bg_wand) DestroyPixelWand (bg_wand); if (bg_wand) DestroyPixelWand (bg_wand);
if (filename_hint)
free (filename_hint);
MagickWandTerminus (); MagickWandTerminus ();
/* TODO more cleanup. */ /* TODO more cleanup. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment