Fix potential memory leak in Cycles loading of packed/generated images.

This commit is contained in:
Brecht Van Lommel 2017-07-20 22:31:02 +02:00
parent 3b12a71972
commit a4cd7b7297
1 changed files with 9 additions and 2 deletions

View File

@ -1115,7 +1115,6 @@ bool BlenderSession::builtin_image_pixels(const string &builtin_name,
if(image_pixels && num_pixels * channels == pixels_size) {
memcpy(pixels, image_pixels, pixels_size * sizeof(unsigned char));
MEM_freeN(image_pixels);
}
else {
if(channels == 1) {
@ -1134,6 +1133,11 @@ bool BlenderSession::builtin_image_pixels(const string &builtin_name,
}
}
}
if(image_pixels) {
MEM_freeN(image_pixels);
}
/* Premultiply, byte images are always straight for Blender. */
unsigned char *cp = pixels;
for(size_t i = 0; i < num_pixels; i++, cp += channels) {
@ -1172,7 +1176,6 @@ bool BlenderSession::builtin_image_float_pixels(const string &builtin_name,
if(image_pixels && num_pixels * channels == pixels_size) {
memcpy(pixels, image_pixels, pixels_size * sizeof(float));
MEM_freeN(image_pixels);
}
else {
if(channels == 1) {
@ -1192,6 +1195,10 @@ bool BlenderSession::builtin_image_float_pixels(const string &builtin_name,
}
}
if(image_pixels) {
MEM_freeN(image_pixels);
}
return true;
}
else if(b_id.is_a(&RNA_Object)) {