Evas masking: Make sure to check alloc before freeing old image
authorJean-Philippe Andre <jp.andre@samsung.com>
Mon, 31 Aug 2015 07:46:19 +0000 (16:46 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Fri, 4 Sep 2015 02:11:39 +0000 (11:11 +0900)
Okay, I'm being paranoid and this can't possibly happen (calloc
fail? yeaaaah) but this makes sure we don't return NULL after
freeing the original image.

src/modules/evas/engines/gl_generic/evas_engine.c

index fabd6e0..8211bb6 100644 (file)
@@ -1229,7 +1229,7 @@ eng_image_scaled_update(void *data EINA_UNUSED, void *scaled, void *image,
                         Eina_Bool smooth, Eina_Bool alpha,
                         Evas_Colorspace cspace EINA_UNUSED)
 {
-   Evas_GL_Image *dst = scaled;
+   Evas_GL_Image *dst = scaled, *newdst;
    Evas_GL_Image *src = image;
    Evas_Engine_GL_Context *gc;
    Eina_Bool reffed = EINA_FALSE;
@@ -1266,6 +1266,9 @@ eng_image_scaled_update(void *data EINA_UNUSED, void *scaled, void *image,
         return NULL;
      }
 
+   newdst = calloc(1, sizeof(Evas_GL_Image));
+   if (!newdst) return NULL;
+
    if (dst)
      {
         if (dst->scaled.origin == src)
@@ -1283,24 +1286,21 @@ eng_image_scaled_update(void *data EINA_UNUSED, void *scaled, void *image,
         evas_gl_common_image_free(dst);
      }
 
-   dst = calloc(1, sizeof(Evas_GL_Image));
-   if (!dst) return NULL;
-
-   dst->references = 1;
-   dst->gc = gc;
-   dst->cs.space = src->cs.space;
-   dst->alpha = alpha;
-   dst->w = dst_w;
-   dst->h = dst_h;
-   dst->tex = src->tex;
-   dst->tex->references++;
-   dst->tex_only = 1;
+   newdst->references = 1;
+   newdst->gc = gc;
+   newdst->cs.space = src->cs.space;
+   newdst->alpha = alpha;
+   newdst->w = dst_w;
+   newdst->h = dst_h;
+   newdst->tex = src->tex;
+   newdst->tex->references++;
+   newdst->tex_only = 1;
 
    if (!reffed) src->references++;
-   dst->scaled.origin = src;
-   dst->scaled.smooth = smooth;
+   newdst->scaled.origin = src;
+   newdst->scaled.smooth = smooth;
 
-   return dst;
+   return newdst;
 }
 
 static void