From: Laszlo Boszormenyi (GCS) Date: Mon, 17 Apr 2023 17:17:10 +0000 (+0100) Subject: eliminate_memory_leak_when_handling_EXIFOrientation X-Git-Tag: archive/raspbian/1.4+really1.3.40-4+rpi1^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d301cadeb6f1061b4c51877f0ba46fbfac6564d1;p=graphicsmagick.git eliminate_memory_leak_when_handling_EXIFOrientation # HG changeset patch # User Bob Friesenhahn # Date 1681598921 18000 # Node ID 3ce01217413bb5b476460bbc8ab11020205eeda0 # Parent 8bec800dbaef2d72da0e7e997ad45bece0e95893 SetImageAttribute(): Eliminate memory leak when handling attribute with key "EXIF:Orientation" Gbp-Pq: Name eliminate_memory_leak_when_handling_EXIFOrientation.patch --- diff --git a/ChangeLog b/ChangeLog index 03aa5ae..1266422 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-04-15 Bob Friesenhahn + + * magick/attribute.c (SetImageAttribute): Eliminate memory leak + when handling attribute with key "EXIF:Orientation". (SourceForge + issue #707 "memory leaks in gm"). + 2023-04-08 Bob Friesenhahn * coders/mpc.c (ReadMPCImage): If an attribute appears multiple diff --git a/coders/miff.c b/coders/miff.c index f26b810..f192559 100644 --- a/coders/miff.c +++ b/coders/miff.c @@ -761,6 +761,8 @@ SetNewImageAttribute(Image *image,const char *key,const char *value) MagickPassFail status; + status = SetImageAttribute(image,key,value); + if (GetImageAttribute(image,key) == (const ImageAttribute *) NULL) status = SetImageAttribute(image,key,value); else diff --git a/magick/attribute.c b/magick/attribute.c index d1768fb..9308227 100644 --- a/magick/attribute.c +++ b/magick/attribute.c @@ -3178,9 +3178,6 @@ SetImageAttribute(Image *image,const char *key,const char *value) register ImageAttribute *p; - int - orientation; - /* Initialize new attribute. */ @@ -3271,6 +3268,9 @@ SetImageAttribute(Image *image,const char *key,const char *value) if (LocaleCompare(attribute->key,"EXIF:Orientation") == 0) { + int + orientation = 0; + /* Special handling for EXIF orientation tag. If new value differs from existing value, @@ -3278,17 +3278,19 @@ SetImageAttribute(Image *image,const char *key,const char *value) is valid. Don't append new value to existing value, replace it instead. */ - orientation = MagickAtoI(value); - if (orientation > 0 || orientation <= (int)LeftBottomOrientation) - SetEXIFOrientation(image, orientation); - - /* Replace current attribute with new one */ - attribute->next = p->next; - if (p->previous == (ImageAttribute *) NULL) - image->attributes=attribute; - else - p->previous->next = attribute; - DestroyImageAttribute(p); + if ((MagickAtoIChk(value, &orientation) == MagickPass) && + (orientation > 0 || orientation <= (int)LeftBottomOrientation)) + { + SetEXIFOrientation(image, orientation); + } + /* Assign changed value to attribute in list */ + if (LocaleCompare(p->value, attribute->value) != 0) + { + MagickFreeMemory(p->value); + p->value=attribute->value; + attribute->value = (char *) NULL; + } + DestroyImageAttribute(attribute); return(MagickPass); } else @@ -3296,6 +3298,9 @@ SetImageAttribute(Image *image,const char *key,const char *value) /* Extend existing text string. This functionality is deprecated! */ + fprintf(stderr, + "SetImageAttribute: Extending attribute value text is deprecated! (key=\"%s\")\n", + attribute->key); min_l=p->length+attribute->length+1; for (realloc_l=2; realloc_l <= min_l; realloc_l *= 2) { /* nada */}; diff --git a/www/Changelog.html b/www/Changelog.html index e6abaff..9abae9c 100644 --- a/www/Changelog.html +++ b/www/Changelog.html @@ -37,6 +37,14 @@
+

2023-04-15 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>

+
+
    +
  • magick/attribute.c (SetImageAttribute): Eliminate memory leak +when handling attribute with key "EXIF:Orientation". (SourceForge +issue #707 "memory leaks in gm").

  • +
+

2023-04-08 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>