From dd8e99045144b4828a79eba5a1e592fc489927c0 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 27 Jul 2018 18:41:39 +0300 Subject: [PATCH] Fixed several issues found by static analysis, GStreamer backend --- modules/videoio/src/cap_gstreamer.cpp | 37 ++++++++++----------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/modules/videoio/src/cap_gstreamer.cpp b/modules/videoio/src/cap_gstreamer.cpp index c3100f56f3..8758b21dd9 100644 --- a/modules/videoio/src/cap_gstreamer.cpp +++ b/modules/videoio/src/cap_gstreamer.cpp @@ -1224,7 +1224,11 @@ Ptr cv::createGStreamerCapture(int index) class CvVideoWriter_GStreamer : public CvVideoWriter { public: - CvVideoWriter_GStreamer() { init(); } + CvVideoWriter_GStreamer() + : pipeline(0), source(0), encodebin(0), file(0), buffer(0), input_pix_fmt(0), + num_frames(0), framerate(0) + { + } virtual ~CvVideoWriter_GStreamer() CV_OVERRIDE { close(); } virtual bool open( const char* filename, int fourcc, @@ -1232,7 +1236,6 @@ public: virtual void close(); virtual bool writeFrame( const IplImage* image ) CV_OVERRIDE; protected: - void init(); const char* filenameToMimetype(const char* filename); GstElement* pipeline; GstElement* source; @@ -1245,22 +1248,6 @@ protected: double framerate; }; -/*! - * \brief CvVideoWriter_GStreamer::init - * initialise all variables - */ -void CvVideoWriter_GStreamer::init() -{ - pipeline = NULL; - source = NULL; - encodebin = NULL; - file = NULL; - buffer = NULL; - - num_frames = 0; - framerate = 0; -} - /*! * \brief CvVideoWriter_GStreamer::close * ends the pipeline by sending EOS and destroys the pipeline and all @@ -1282,17 +1269,19 @@ void CvVideoWriter_GStreamer::close() //wait for EOS to trickle down the pipeline. This will let all elements finish properly GstBus* bus = gst_element_get_bus(pipeline); GstMessage *msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS)); - if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_ERROR) + if (!msg || GST_MESSAGE_TYPE(msg) == GST_MESSAGE_ERROR) { CV_WARN("Error during VideoWriter finalization\n"); + if(msg != NULL) + { + gst_message_unref(msg); + g_object_unref(G_OBJECT(bus)); + } return; } - if(msg != NULL) - { - gst_message_unref(msg); - g_object_unref(G_OBJECT(bus)); - } + gst_message_unref(msg); + g_object_unref(G_OBJECT(bus)); status = gst_element_set_state (pipeline, GST_STATE_NULL); if (status == GST_STATE_CHANGE_ASYNC)