fix memory leak when baking feedback loop detected.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 12 Sep 2012 03:11:29 +0000 (03:11 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 12 Sep 2012 03:11:29 +0000 (03:11 +0000)
source/blender/editors/object/object_bake.c

index 59cc782f3ebe1bae4e850c953e8ede5f4b79e40f..c0dd911946b1b973a15e0e991b93329bc3476a8b 100644 (file)
@@ -1347,6 +1347,8 @@ static void init_bake_internal(BakeRender *bkr, bContext *C)
 
 static void finish_bake_internal(BakeRender *bkr)
 {
+       Image *ima;
+
        RE_Database_Free(bkr->re);
 
        /* restore raytrace and AO */
@@ -1358,26 +1360,27 @@ static void finish_bake_internal(BakeRender *bkr)
                if (bkr->prev_r_raytrace == 0)
                        bkr->scene->r.mode &= ~R_RAYTRACE;
 
-       if (bkr->result == BAKE_RESULT_OK) {
-               Image *ima;
-               /* force OpenGL reload and mipmap recalc */
-               for (ima = G.main->image.first; ima; ima = ima->id.next) {
+
+       /* force OpenGL reload and mipmap recalc */
+       for (ima = G.main->image.first; ima; ima = ima->id.next) {
+               ImBuf *ibuf = BKE_image_get_ibuf(ima, NULL);
+
+               if (bkr->result == BAKE_RESULT_OK) {
                        if (ima->ok == IMA_OK_LOADED) {
-                               ImBuf *ibuf = BKE_image_get_ibuf(ima, NULL);
                                if (ibuf) {
                                        if (ibuf->userflags & IB_BITMAPDIRTY) {
                                                GPU_free_image(ima);
                                                imb_freemipmapImBuf(ibuf);
                                        }
-
-                                       /* freed when baking is done, but if its canceled we need to free here */
-                                       if (ibuf->userdata) {
-                                               MEM_freeN(ibuf->userdata);
-                                               ibuf->userdata = NULL;
-                                       }
                                }
                        }
                }
+
+               /* freed when baking is done, but if its canceled we need to free here */
+               if (ibuf->userdata) {
+                       MEM_freeN(ibuf->userdata);
+                       ibuf->userdata = NULL;
+               }
        }
 }