From e5dae7e602f9e5481a6db4d65a7cfacd810fcec4 Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthm@freeswitch.org>
Date: Mon, 20 Apr 2015 11:04:36 -0500
Subject: [PATCH] FS-7513: prevent null layer img

---
 .../mod_conference/mod_conference.c             | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c
index 4ab6edde9a..d59ea1855d 100644
--- a/src/mod/applications/mod_conference/mod_conference.c
+++ b/src/mod/applications/mod_conference/mod_conference.c
@@ -1044,6 +1044,8 @@ static void scale_and_patch(conference_obj_t *conference, mcu_layer_t *layer, sw
 	IMG = conference->canvas->img;
 	img = ximg ? ximg : layer->cur_img;
 
+	switch_assert(IMG && img);
+
 	if (layer->refresh) {
 		switch_rgb_color_t color;
 		switch_color_set_rgb(&color, conference->video_layout_bgcolor);
@@ -2002,17 +2004,20 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
 							if (img != imember->avatar_png_img) {
 								switch_img_free(&img);
 							}
-
-						} else {
-							layer->cur_img = img;
+							
 						}
 
+						if (img && !layer->cur_img) {
+							layer->cur_img = img;
+						}
+						
 						img = NULL;
 						layer->tagged = 1;
 					}
 				}
 
 				switch_mutex_unlock(conference->canvas->mutex);
+
 				if (img && img != imember->avatar_png_img) {
 					switch_img_free(&img);
 				}
@@ -2045,8 +2050,10 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
 						layer->refresh = 1;
 						conference->canvas->refresh++;
 					}
-
-					scale_and_patch(conference, layer, NULL, SWITCH_FALSE);
+					
+					if (layer->cur_img) {
+						scale_and_patch(conference, layer, NULL, SWITCH_FALSE);
+					}
 					layer->tagged = 0;
 				}
 			}