[Bf-blender-cvs] [461604c] master: Fix (unreported) bad 'NULL freeing' with placeholder images.

Bastien Montagne noreply at git.blender.org
Fri Apr 29 18:07:55 CEST 2016


Commit: 461604c0d5ea58bb44a2fac0a3637f5b959aac26
Author: Bastien Montagne
Date:   Fri Apr 29 18:05:49 2016 +0200
Branches: master
https://developer.blender.org/rB461604c0d5ea58bb44a2fac0a3637f5b959aac26

Fix (unreported) bad 'NULL freeing' with placeholder images.

Looks like code expects some initialized Image data after all, so do it
for placeholders as well (using default generated UV grid).

===================================================================

M	source/blender/blenkernel/BKE_image.h
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/library.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index 894ccae..eb98268 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -61,6 +61,8 @@ void    BKE_image_free_buffers(struct Image *image);
 /* call from library */
 void    BKE_image_free(struct Image *image);
 
+void    BKE_image_init(struct Image *image);
+
 typedef void (StampCallback)(void *data, const char *propname, char *propvalue, int len);
 
 void    BKE_render_result_stamp_info(struct Scene *scene, struct Object *camera, struct RenderResult *rr, bool allocate_only);
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 340b406..d5f9a2d 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -350,27 +350,41 @@ void BKE_image_free(Image *ima)
 }
 
 /* only image block itself */
-static Image *image_alloc(Main *bmain, const char *name, short source, short type)
+static void image_init(Image *ima, short source, short type)
 {
-	Image *ima;
+	BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ima, id));
 
-	ima = BKE_libblock_alloc(bmain, ID_IM, name);
-	if (ima) {
-		ima->ok = IMA_OK;
+	ima->ok = IMA_OK;
 
-		ima->xrep = ima->yrep = 1;
-		ima->aspx = ima->aspy = 1.0;
-		ima->gen_x = 1024; ima->gen_y = 1024;
-		ima->gen_type = 1;   /* no defines yet? */
+	ima->xrep = ima->yrep = 1;
+	ima->aspx = ima->aspy = 1.0;
+	ima->gen_x = 1024; ima->gen_y = 1024;
+	ima->gen_type = IMA_GENTYPE_GRID;
 
-		ima->source = source;
-		ima->type = type;
+	ima->source = source;
+	ima->type = type;
 
-		if (source == IMA_SRC_VIEWER)
-			ima->flag |= IMA_VIEW_AS_RENDER;
+	if (source == IMA_SRC_VIEWER)
+		ima->flag |= IMA_VIEW_AS_RENDER;
 
-		BKE_color_managed_colorspace_settings_init(&ima->colorspace_settings);
-		ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo Format");
+	BKE_color_managed_colorspace_settings_init(&ima->colorspace_settings);
+	ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo Format");
+}
+
+void BKE_image_init(struct Image *image)
+{
+	if (image) {
+		image_init(image, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST);
+	}
+}
+
+static Image *image_alloc(Main *bmain, const char *name, short source, short type)
+{
+	Image *ima;
+
+	ima = BKE_libblock_alloc(bmain, ID_IM, name);
+	if (ima) {
+		image_init(ima, source, type);
 	}
 
 	return ima;
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 895d215..9e81cde 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -931,7 +931,7 @@ void BKE_libblock_init_empty(ID *id)
 			BKE_texture_default((Tex *)id);
 			break;
 		case ID_IM:
-			/* Image is a bit complicated, for now assume NULLified im is OK. */
+			BKE_image_init((Image *)id);
 			break;
 		case ID_LT:
 			BKE_lattice_init((Lattice *)id);




More information about the Bf-blender-cvs mailing list