changeset 31725:8e850ff84b27

Allocate memory for paletted image data separately to avoid issues with e.g. the "cut" function.
author reimar
date Sat, 24 Jul 2010 21:40:06 +0000
parents 2e98a0ed97c8
children 8adcdb0b8ef6
files spudec.c
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/spudec.c	Sat Jul 24 21:34:13 2010 +0000
+++ b/spudec.c	Sat Jul 24 21:40:06 2010 +0000
@@ -228,13 +228,15 @@
   if (this->image_size < this->stride * this->height) {
     if (this->image != NULL) {
       free(this->image);
+      free(this->pal_image);
       this->image_size = 0;
     }
-    this->image = malloc(3 * this->stride * this->height);
+    this->image = malloc(2 * this->stride * this->height);
     if (this->image) {
       this->image_size = this->stride * this->height;
       this->aimage = this->image + this->image_size;
-      this->pal_image = this->aimage + this->image_size;
+      // use stride here as well to simplify reallocation checks
+      this->pal_image = malloc(this->stride * this->height);
     }
   }
   return this->image != NULL;
@@ -1269,6 +1271,7 @@
 	free(spu->scaled_image);
     if (spu->image)
       free(spu->image);
+    free(spu->pal_image);
     free(spu);
   }
 }