camerabin2: Check before acessing preview location list
authorThiago Santos <thiago.sousa.santos@collabora.com>
Wed, 12 Oct 2011 15:09:18 +0000 (12:09 -0300)
committerThiago Santos <thiago.sousa.santos@collabora.com>
Wed, 12 Oct 2011 15:19:13 +0000 (12:19 -0300)
Only access the preview location if it exists, to avoid acessing
a NULL variable. If the preview location list doesn't exist, it is
likely because the source has posted a preview message after camerabin2
has been put to READY.

gst/camerabin2/gstcamerabin2.c

index fcd98be..8d1de91 100644 (file)
@@ -949,22 +949,31 @@ gst_camera_bin_handle_message (GstBin * bin, GstMessage * message)
         }
       } else if (gst_structure_has_name (structure, "preview-image")) {
         GValue *value;
-        gchar *location;
+        gchar *location = NULL;
 
         g_mutex_lock (camerabin->preview_list_mutex);
-        location = camerabin->preview_location_list->data;
-        camerabin->preview_location_list =
-            g_slist_delete_link (camerabin->preview_location_list,
-            camerabin->preview_location_list);
-        GST_DEBUG_OBJECT (camerabin, "Adding preview location to preview "
-            "message '%s'", location);
+        if (camerabin->preview_location_list) {
+          location = camerabin->preview_location_list->data;
+          camerabin->preview_location_list =
+              g_slist_delete_link (camerabin->preview_location_list,
+              camerabin->preview_location_list);
+          GST_DEBUG_OBJECT (camerabin, "Adding preview location to preview "
+              "message '%s'", location);
+        } else {
+          GST_WARNING_OBJECT (camerabin, "Unexpected preview message received, "
+              "won't be able to put location field into the message. This can "
+              "happen if the source is posting previews while camerabin2 is "
+              "shutting down");
+        }
         g_mutex_unlock (camerabin->preview_list_mutex);
 
-        value = g_new0 (GValue, 1);
-        g_value_init (value, G_TYPE_STRING);
-        g_value_take_string (value, location);
-        gst_structure_take_value ((GstStructure *) structure, "location",
-            value);
+        if (location) {
+          value = g_new0 (GValue, 1);
+          g_value_init (value, G_TYPE_STRING);
+          g_value_take_string (value, location);
+          gst_structure_take_value ((GstStructure *) structure, "location",
+              value);
+        }
       }
     }
       break;