aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2013-08-14 00:00:25 -0700
committerPaul Eggert2013-08-14 00:00:25 -0700
commit01c3051fc39127302943846f15047da305c07df0 (patch)
tree9dd6da012f924c380e0ddea8f075e3c814bb91bf /src
parent2084152aee6fe88fda43ffb5fd654aeae5d12129 (diff)
downloademacs-01c3051fc39127302943846f15047da305c07df0.tar.gz
emacs-01c3051fc39127302943846f15047da305c07df0.zip
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/image.c69
2 files changed, 35 insertions, 40 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 88df9f13762..30a3dc3462b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
12013-08-14 Paul Eggert <eggert@cs.ucla.edu>
2
3 * image.c (imagemagick_filename_hint): New arg HINT_BUFFER.
4 Use changed. This avoids the need to call xmalloc and for the
5 caller to call xfree, and avoids memory leaks in some situations.
6
12013-08-14 Dmitry Antipov <dmantipov@yandex.ru> 72013-08-14 Dmitry Antipov <dmantipov@yandex.ru>
2 8
3 * xdisp.c (adjust_window_ends): Move duplicated code to new function. 9 * xdisp.c (adjust_window_ends): Move duplicated code to new function.
diff --git a/src/image.c b/src/image.c
index 99bb9d8c135..d93d1b517bf 100644
--- a/src/image.c
+++ b/src/image.c
@@ -7845,35 +7845,27 @@ imagemagick_error (MagickWand *wand)
7845} 7845}
7846 7846
7847/* Possibly give ImageMagick some extra help to determine the image 7847/* Possibly give ImageMagick some extra help to determine the image
7848 type by supplying a "dummy" filename based on the Content-Type. */ 7848 type by supplying a "dummy" filename based on the Content-Type. */
7849 7849
7850static char* 7850static char *
7851imagemagick_filename_hint (Lisp_Object spec) 7851imagemagick_filename_hint (Lisp_Object spec, char hint_buffer[MaxTextExtent])
7852{ 7852{
7853 Lisp_Object format = image_spec_value (spec, intern (":format"), NULL); 7853 Lisp_Object symbol = intern ("image-format-suffixes");
7854 Lisp_Object val, symbol = intern ("image-format-suffixes"); 7854 Lisp_Object val = find_symbol_value (symbol);
7855 const char *prefix = "/tmp/foo."; 7855 Lisp_Object format;
7856 char *name;
7857 7856
7858 if (NILP (Fboundp (symbol)))
7859 return NULL;
7860
7861 val = Fassq (format, Fsymbol_value (symbol));
7862 if (! CONSP (val))
7863 return NULL;
7864
7865 val = Fcdr (val);
7866 if (! CONSP (val)) 7857 if (! CONSP (val))
7867 return NULL; 7858 return NULL;
7868 7859
7869 val = Fcar (val); 7860 format = image_spec_value (spec, intern (":format"), NULL);
7861 val = Fcar_safe (Fcdr_safe (Fassq (format, val)));
7870 if (! STRINGP (val)) 7862 if (! STRINGP (val))
7871 return NULL; 7863 return NULL;
7872 7864
7873 name = xmalloc (strlen (prefix) + SBYTES (val) + 1); 7865 /* It's OK to truncate the hint if it has MaxTextExtent or more bytes,
7874 strcpy (name, prefix); 7866 as ImageMagick would ignore the extra bytes anyway. */
7875 strcat (name, SSDATA (val)); 7867 snprintf (hint_buffer, MaxTextExtent, "/tmp/foo.%s", SSDATA (val));
7876 return name; 7868 return hint_buffer;
7877} 7869}
7878 7870
7879/* Helper function for imagemagick_load, which does the actual loading 7871/* Helper function for imagemagick_load, which does the actual loading
@@ -7909,6 +7901,7 @@ imagemagick_load_image (struct frame *f, struct image *img,
7909 int desired_width, desired_height; 7901 int desired_width, desired_height;
7910 double rotation; 7902 double rotation;
7911 int pixelwidth; 7903 int pixelwidth;
7904 char hint_buffer[MaxTextExtent];
7912 char *filename_hint = NULL; 7905 char *filename_hint = NULL;
7913 7906
7914 /* Handle image index for image types who can contain more than one image. 7907 /* 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 ping_wand = NewMagickWand (); 7916 ping_wand = NewMagickWand ();
7924 /* MagickSetResolution (ping_wand, 2, 2); (Bug#10112) */ 7917 /* MagickSetResolution (ping_wand, 2, 2); (Bug#10112) */
7925 7918
7926 if (! filename) 7919 if (filename)
7927 filename_hint = imagemagick_filename_hint (img->spec); 7920 status = MagickPingImage (ping_wand, filename);
7928 7921 else
7929 if (filename_hint) 7922 {
7930 MagickSetFilename (ping_wand, filename_hint); 7923 filename_hint = imagemagick_filename_hint (img->spec, hint_buffer);
7931 7924 MagickSetFilename (ping_wand, filename_hint);
7932 status = filename 7925 status = MagickPingImageBlob (ping_wand, contents, size);
7933 ? MagickPingImage (ping_wand, filename) 7926 }
7934 : MagickPingImageBlob (ping_wand, contents, size);
7935 7927
7936 if (status == MagickFalse) 7928 if (status == MagickFalse)
7937 { 7929 {
@@ -7961,13 +7953,15 @@ imagemagick_load_image (struct frame *f, struct image *img,
7961 7953
7962 image_wand = NewMagickWand (); 7954 image_wand = NewMagickWand ();
7963 7955
7964 if (filename_hint) 7956 if (filename)
7965 MagickSetFilename (image_wand, filename_hint); 7957 status = MagickReadImage (image_wand, filename);
7958 else
7959 {
7960 MagickSetFilename (image_wand, filename_hint);
7961 status = MagickReadImageBlob (image_wand, contents, size);
7962 }
7966 7963
7967 if ((filename 7964 if (status == MagickFalse)
7968 ? MagickReadImage (image_wand, filename)
7969 : MagickReadImageBlob (image_wand, contents, size))
7970 == MagickFalse)
7971 { 7965 {
7972 imagemagick_error (image_wand); 7966 imagemagick_error (image_wand);
7973 goto imagemagick_error; 7967 goto imagemagick_error;
@@ -8207,16 +8201,11 @@ imagemagick_load_image (struct frame *f, struct image *img,
8207 /* `MagickWandTerminus' terminates the imagemagick environment. */ 8201 /* `MagickWandTerminus' terminates the imagemagick environment. */
8208 MagickWandTerminus (); 8202 MagickWandTerminus ();
8209 8203
8210 if (filename_hint)
8211 free (filename_hint);
8212
8213 return 1; 8204 return 1;
8214 8205
8215 imagemagick_error: 8206 imagemagick_error:
8216 DestroyMagickWand (image_wand); 8207 DestroyMagickWand (image_wand);
8217 if (bg_wand) DestroyPixelWand (bg_wand); 8208 if (bg_wand) DestroyPixelWand (bg_wand);
8218 if (filename_hint)
8219 free (filename_hint);
8220 8209
8221 MagickWandTerminus (); 8210 MagickWandTerminus ();
8222 /* TODO more cleanup. */ 8211 /* TODO more cleanup. */