camerabin2: Check before acessing preview location list

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.
This commit is contained in:
Thiago Santos 2011-10-12 12:09:18 -03:00
parent 94d9327e2a
commit 61a7e6bf38

View 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;