From 211c8492b35d1e58033d9104ec8b52d497f475fb Mon Sep 17 00:00:00 2001 From: Dave Craig Date: Wed, 16 Dec 2015 12:40:39 +0000 Subject: gst: Don't assume that get_current_caps() returns non-NULL caps after has_current_caps() Remove calls to gst_pad_has_current_caps() which then go on to call gst_pad_get_current_caps() as the caps can go to NULL in between. Instead just use gst_pad_get_current_caps() and check for NULL. https://bugzilla.gnome.org/show_bug.cgi?id=759539 --- ext/flac/gstflacenc.c | 10 ++++------ gst/flv/gstflvmux.c | 9 ++++++--- gst/imagefreeze/gstimagefreeze.c | 4 ++-- gst/rtp/gstrtph264depay.c | 7 ++++--- gst/shapewipe/gstshapewipe.c | 21 +++++++++++++-------- gst/videocrop/gstaspectratiocrop.c | 6 ++++-- 6 files changed, 33 insertions(+), 24 deletions(-) diff --git a/ext/flac/gstflacenc.c b/ext/flac/gstflacenc.c index dae0172a0..0e3940fa6 100644 --- a/ext/flac/gstflacenc.c +++ b/ext/flac/gstflacenc.c @@ -766,9 +766,8 @@ gst_flac_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter) pad = GST_AUDIO_ENCODER_SINK_PAD (enc); - if (gst_pad_has_current_caps (pad)) { - ret = gst_pad_get_current_caps (pad); - } else { + ret = gst_pad_get_current_caps (pad); + if (ret == NULL) { ret = gst_pad_get_pad_template_caps (pad); } @@ -1281,9 +1280,8 @@ gst_flac_enc_sink_query (GstAudioEncoder * enc, GstQuery * query) case GST_QUERY_ACCEPT_CAPS:{ GstCaps *acceptable, *caps; - if (gst_pad_has_current_caps (pad)) { - acceptable = gst_pad_get_current_caps (pad); - } else { + acceptable = gst_pad_get_current_caps (pad); + if (acceptable == NULL) { acceptable = gst_pad_get_pad_template_caps (pad); } diff --git a/gst/flv/gstflvmux.c b/gst/flv/gstflvmux.c index 95dc449a4..48f8b6604 100644 --- a/gst/flv/gstflvmux.c +++ b/gst/flv/gstflvmux.c @@ -830,6 +830,7 @@ tags: if (mux->have_video) { GstPad *video_pad = NULL; + GstCaps *caps = NULL; GstFlvPad *cpad; GSList *l = mux->collect->data; @@ -841,8 +842,11 @@ tags: } } - if (video_pad && gst_pad_has_current_caps (video_pad)) { - GstCaps *caps; + if (video_pad) { + caps = gst_pad_get_current_caps (video_pad); + } + + if (caps != NULL) { GstStructure *s; gint size; gint num, den; @@ -855,7 +859,6 @@ tags: script_tag = gst_buffer_append (script_tag, tmp); tags_written++; - caps = gst_pad_get_current_caps (video_pad); s = gst_caps_get_structure (caps, 0); gst_caps_unref (caps); diff --git a/gst/imagefreeze/gstimagefreeze.c b/gst/imagefreeze/gstimagefreeze.c index bc8bf8167..8b1bfc5b1 100644 --- a/gst/imagefreeze/gstimagefreeze.c +++ b/gst/imagefreeze/gstimagefreeze.c @@ -265,8 +265,8 @@ gst_image_freeze_sink_getcaps (GstImageFreeze * self, GstCaps * filter) GstPad *pad; pad = self->sinkpad; - if (gst_pad_has_current_caps (pad)) { - ret = gst_pad_get_current_caps (pad); + ret = gst_pad_get_current_caps (pad); + if (ret != NULL) { goto done; } diff --git a/gst/rtp/gstrtph264depay.c b/gst/rtp/gstrtph264depay.c index 234369672..57ed5248b 100644 --- a/gst/rtp/gstrtph264depay.c +++ b/gst/rtp/gstrtph264depay.c @@ -267,6 +267,7 @@ gst_rtp_h264_set_src_caps (GstRtpH264Depay * rtph264depay) { gboolean res; GstCaps *srccaps; + GstCaps *old_caps; if (!rtph264depay->byte_stream && (!rtph264depay->new_codec_data || @@ -397,10 +398,10 @@ gst_rtp_h264_set_src_caps (GstRtpH264Depay * rtph264depay) } - if (gst_pad_has_current_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (rtph264depay))) { - GstCaps *old_caps = - gst_pad_get_current_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (rtph264depay)); + old_caps = + gst_pad_get_current_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (rtph264depay)); + if (old_caps != NULL) { /* Only update the caps if they are not equal. For * AVC we don't update caps if only the codec_data * changes. This is the same behaviour as in h264parse diff --git a/gst/shapewipe/gstshapewipe.c b/gst/shapewipe/gstshapewipe.c index 5d4fa94de..1a82a504c 100644 --- a/gst/shapewipe/gstshapewipe.c +++ b/gst/shapewipe/gstshapewipe.c @@ -329,8 +329,9 @@ gst_shape_wipe_video_sink_getcaps (GstShapeWipe * self, GstPad * pad, { GstCaps *templ, *ret, *tmp; - if (gst_pad_has_current_caps (pad)) - return gst_pad_get_current_caps (pad); + ret = gst_pad_get_current_caps (pad); + if (ret != NULL) + return ret; templ = gst_pad_get_pad_template_caps (pad); tmp = gst_pad_peer_query_caps (self->srcpad, NULL); @@ -451,8 +452,9 @@ gst_shape_wipe_mask_sink_getcaps (GstShapeWipe * self, GstPad * pad, GstCaps *ret, *tmp, *tcaps; guint i, n; - if (gst_pad_has_current_caps (pad)) - return gst_pad_get_current_caps (pad); + ret = gst_pad_get_current_caps (pad); + if (ret != NULL) + return ret; tcaps = gst_pad_get_pad_template_caps (self->video_sinkpad); tmp = gst_pad_peer_query_caps (self->video_sinkpad, NULL); @@ -535,10 +537,13 @@ gst_shape_wipe_src_getcaps (GstPad * pad, GstCaps * filter) GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad)); GstCaps *templ, *ret, *tmp; - if (gst_pad_has_current_caps (pad)) - return gst_pad_get_current_caps (pad); - else if (gst_pad_has_current_caps (self->video_sinkpad)) - return gst_pad_get_current_caps (self->video_sinkpad); + ret = gst_pad_get_current_caps (pad); + if (ret != NULL) + return ret; + + ret = gst_pad_get_current_caps (self->video_sinkpad); + if (ret != NULL) + return ret; templ = gst_pad_get_pad_template_caps (self->video_sinkpad); tmp = gst_pad_peer_query_caps (self->video_sinkpad, NULL); diff --git a/gst/videocrop/gstaspectratiocrop.c b/gst/videocrop/gstaspectratiocrop.c index 10d0499aa..037d32645 100644 --- a/gst/videocrop/gstaspectratiocrop.c +++ b/gst/videocrop/gstaspectratiocrop.c @@ -464,8 +464,10 @@ gst_aspect_ratio_crop_set_property (GObject * object, guint prop_id, if (recheck) { GstCaps *caps = gst_pad_get_current_caps (aspect_ratio_crop->sink); - gst_aspect_ratio_crop_set_caps (aspect_ratio_crop, caps); - gst_caps_unref (caps); + if (caps != NULL) { + gst_aspect_ratio_crop_set_caps (aspect_ratio_crop, caps); + gst_caps_unref (caps); + } } } -- cgit v1.2.1