From 519e0050e554fa4865e59f1e79a6c9a4f0deecb7 Mon Sep 17 00:00:00 2001 From: Cristy Date: Sun, 16 Oct 2016 15:28:40 -0400 Subject: [PATCH] GetMagickHomeURL() no longer leaks memory --- MagickCore/resize.c | 6 ++++-- MagickCore/version.c | 6 +++++- coders/dpx.c | 10 +++++++--- coders/fits.c | 8 +++++--- coders/json.c | 7 ++++++- coders/pdf.c | 15 ++++++++++----- coders/wmf.c | 7 +++++-- configure | 4 ++-- configure.ac | 2 +- 9 files changed, 45 insertions(+), 20 deletions(-) diff --git a/MagickCore/resize.c b/MagickCore/resize.c index ca95ae5d4..d48cf88bc 100644 --- a/MagickCore/resize.c +++ b/MagickCore/resize.c @@ -3630,6 +3630,7 @@ MagickExport Image *ThumbnailImage(const Image *image,const size_t columns, #define SampleFactor 5 char + *url, value[MagickPathExtent]; const char @@ -3712,8 +3713,9 @@ MagickExport Image *ThumbnailImage(const Image *image,const size_t columns, (void) FormatLocaleString(value,MagickPathExtent,"image/%s",image->magick); LocaleLower(value); (void) SetImageProperty(thumbnail_image,"Thumb::Mimetype",value,exception); - (void) SetImageProperty(thumbnail_image,"software",GetMagickHomeURL(), - exception); + url=GetMagickHomeURL(); + (void) SetImageProperty(thumbnail_image,"software",url,exception); + url=DestroyString(url); (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double) image->magick_columns); (void) SetImageProperty(thumbnail_image,"Thumb::Image::Width",value, diff --git a/MagickCore/version.c b/MagickCore/version.c index 7127a82ce..256bdaa64 100644 --- a/MagickCore/version.c +++ b/MagickCore/version.c @@ -292,9 +292,13 @@ MagickExport char *GetMagickHomeURL(void) (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",element, DirectorySeparator,MagickURLFilename); if (IsPathAccessible(path) != MagickFalse) - return(ConstantString(path)); + { + paths=DestroyLinkedList(paths,RelinquishMagickMemory); + return(ConstantString(path)); + } element=(const char *) GetNextValueInLinkedList(paths); } + paths=DestroyLinkedList(paths,RelinquishMagickMemory); return(ConstantString(MagickHomeURL)); } diff --git a/coders/dpx.c b/coders/dpx.c index b4a5fde0e..c1c18a952 100644 --- a/coders/dpx.c +++ b/coders/dpx.c @@ -442,7 +442,7 @@ static size_t GetBytesPerRow(const size_t columns, case 16: { if (pad == MagickFalse) - { + { bytes_per_row=2*(((size_t) samples_per_pixel*columns*bits_per_pixel+ 15)/16); break; @@ -1440,6 +1440,9 @@ static inline const char *GetDPXProperty(const Image *image, static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image, ExceptionInfo *exception) { + char + *url; + const char *value; @@ -1565,8 +1568,9 @@ static MagickBooleanType WriteDPXImage(const ImageInfo *image_info,Image *image, dpx.file.timestamp); offset+=WriteBlob(image,sizeof(dpx.file.timestamp),(unsigned char *) dpx.file.timestamp); - (void) strncpy(dpx.file.creator,GetMagickHomeURL(),sizeof(dpx.file.creator)- - 1); + url=GetMagickHomeURL(); + (void) strncpy(dpx.file.creator,url,sizeof(dpx.file.creator)-1); + url=DestroyString(url); value=GetDPXProperty(image,"dpx:file.creator",exception); if (value != (const char *) NULL) (void) strncpy(dpx.file.creator,value,sizeof(dpx.file.creator)-1); diff --git a/coders/fits.c b/coders/fits.c index 17c8704eb..ff4120afd 100644 --- a/coders/fits.c +++ b/coders/fits.c @@ -610,8 +610,9 @@ static MagickBooleanType WriteFITSImage(const ImageInfo *image_info, Image *image,ExceptionInfo *exception) { char + *fits_info, header[FITSBlocksize], - *fits_info; + *url; MagickBooleanType status; @@ -712,8 +713,9 @@ static MagickBooleanType WriteFITSImage(const ImageInfo *image_info, (void) strncpy(fits_info+offset,header,strlen(header)); offset+=80; } - (void) FormatLocaleString(header,FITSBlocksize,"HISTORY %.72s", - GetMagickHomeURL()); + url=GetMagickHomeURL(); + (void) FormatLocaleString(header,FITSBlocksize,"HISTORY %.72s",url); + url=DestroyString(url); (void) strncpy(fits_info+offset,header,strlen(header)); offset+=80; (void) strncpy(header,"END",FITSBlocksize); diff --git a/coders/json.c b/coders/json.c index ee43d7d72..e02d77370 100644 --- a/coders/json.c +++ b/coders/json.c @@ -704,6 +704,9 @@ static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file, ChannelStatistics *channel_statistics; + char + *url; + ColorspaceType colorspace; @@ -1569,7 +1572,9 @@ static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file, (unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod( elapsed_time,60.0)),(unsigned long) (1000.0*(elapsed_time-floor( elapsed_time)))); - JsonFormatLocaleFile(file," \"version\": %s\n",GetMagickHomeURL()); + url=GetMagickHomeURL(); + JsonFormatLocaleFile(file," \"version\": %s\n",url); + url=DestroyString(url); (void) FormatLocaleFile(file," }\n}\n"); (void) fflush(file); return(ferror(file) != 0 ? MagickFalse : MagickTrue); diff --git a/coders/pdf.c b/coders/pdf.c index 696588c84..f46869306 100644 --- a/coders/pdf.c +++ b/coders/pdf.c @@ -1201,7 +1201,8 @@ RestoreMSCWarning buffer[MagickPathExtent], date[MagickPathExtent], **labels, - page_geometry[MagickPathExtent]; + page_geometry[MagickPathExtent], + *url; CompressionType compression; @@ -1360,6 +1361,7 @@ RestoreMSCWarning create_date[MagickPathExtent], modify_date[MagickPathExtent], timestamp[MagickPathExtent], + *url, xmp_profile[MagickPathExtent]; /* @@ -1380,10 +1382,11 @@ RestoreMSCWarning if (value != (const char *) NULL) (void) CopyMagickString(create_date,value,MagickPathExtent); (void) FormatMagickTime(time((time_t *) NULL),MagickPathExtent,timestamp); + url=GetMagickHomeURL(); i=FormatLocaleString(xmp_profile,MagickPathExtent,XMPProfile, - XMPProfileMagick,modify_date,create_date,timestamp, - GetMagickHomeURL(),EscapeParenthesis(basename), - GetMagickHomeURL()); + XMPProfileMagick,modify_date,create_date,timestamp,url, + EscapeParenthesis(basename),url); + url=DestroyString(url); (void) FormatLocaleString(buffer,MagickPathExtent,"/Length %.20g\n", (double) i); (void) WriteBlobString(image,buffer); @@ -2836,8 +2839,10 @@ RestoreMSCWarning (void) WriteBlobString(image,buffer); (void) FormatLocaleString(buffer,MagickPathExtent,"/ModDate (%s)\n",date); (void) WriteBlobString(image,buffer); + url=GetMagickHomeURL(); (void) FormatLocaleString(buffer,MagickPathExtent,"/Producer (%s)\n", - EscapeParenthesis(GetMagickHomeURL())); + EscapeParenthesis(url)); + url=DestroyString(url); (void) WriteBlobString(image,buffer); (void) WriteBlobString(image,">>\n"); (void) WriteBlobString(image,"endobj\n"); diff --git a/coders/wmf.c b/coders/wmf.c index 4524bec19..0714caafe 100644 --- a/coders/wmf.c +++ b/coders/wmf.c @@ -827,7 +827,8 @@ static void ipa_device_close(wmfAPI * API) static void ipa_device_begin(wmfAPI * API) { char - comment[MagickPathExtent]; + comment[MagickPathExtent], + *url; wmf_magick_t *ddata = WMF_MAGICK_GetData(API); @@ -837,8 +838,10 @@ static void ipa_device_begin(wmfAPI * API) DrawSetViewbox(WmfDrawingWand,0,0,ddata->image->columns,ddata->image->rows); + url=GetMagickHomeURL(); (void) FormatLocaleString(comment,MagickPathExtent, - "Created by ImageMagick %s",GetMagickHomeURL()); + "Created by ImageMagick %s",url); + url=DestroyString(url); DrawComment(WmfDrawingWand,comment); /* Scale width and height to image */ diff --git a/configure b/configure index 642c699cd..cd38e78c6 100755 --- a/configure +++ b/configure @@ -1947,7 +1947,7 @@ Optional Features: --enable-prof enable 'prof' profiling support --enable-gprof enable 'gprof' profiling support --enable-gcov enable 'gcov' profiling support - --enable-legacy-support install legacy command-line utilities (default disabled) + --enable-legacy-support install legacy command-line utilities (default disabled) --disable-assert turn off assertions --disable-docs disable building of documentation @@ -4517,7 +4517,7 @@ MAGICK_PATCHLEVEL_VERSION=5 MAGICK_VERSION=7.0.3-5 -MAGICK_GIT_REVISION=18937:83da034:20161010 +MAGICK_GIT_REVISION=18940:62e5ca5:20161016 # Substitute library versioning diff --git a/configure.ac b/configure.ac index 7dbe4f0c6..21bc09061 100644 --- a/configure.ac +++ b/configure.ac @@ -774,7 +774,7 @@ fi # Enable legacy support (default no) AC_ARG_ENABLE(legacy-support, - [ --enable-legacy-support install legacy command-line utilities (default disabled)], + [ --enable-legacy-support install legacy command-line utilities (default disabled)], [with_legacy_support=$enableval], [with_legacy_support='no']) AM_CONDITIONAL(LEGACY_SUPPORT, test "$with_legacy_support" != 'no') -- 2.49.0