2005-11-01 Thomas Vander Stichele <thomas at apestaart dot org>
+ * check/elements/matroskamux.c: (setup_src_pad), (setup_sink_pad),
+ (setup_matroskamux), (check_buffer_data), (GST_START_TEST):
+ * gst/matroska/matroska-mux.c: (gst_matroska_mux_finalize),
+ (gst_matroska_mux_reset), (gst_matroska_mux_audio_pad_setcaps),
+ (gst_matroska_mux_start), (gst_matroska_mux_write_data),
+ (gst_matroska_mux_collected):
+ Fix leaks and invalid memory access as reported by valgrind
+
+2005-11-01 Thomas Vander Stichele <thomas at apestaart dot org>
+
Patch by: Michal Benes <michal.benes@xeris.cz>
* check/Makefile.am:
GstPad *
setup_src_pad (GstElement * element,
- GstStaticPadTemplate * srctemplate, GstCaps * caps)
+ GstStaticPadTemplate * template, GstCaps * caps)
{
GstPad *srcpad, *sinkpad;
+ GstPadTemplate *templ;
GST_DEBUG_OBJECT (element, "setting up sending pad");
/* sending pad */
- srcpad =
- gst_pad_new_from_template (gst_static_pad_template_get (srctemplate),
- "src");
+ templ = gst_static_pad_template_get (template);
+ srcpad = gst_pad_new_from_template (templ, "src");
+ gst_object_unref (templ);
fail_if (srcpad == NULL, "Could not create a srcpad");
ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
GstCaps * caps)
{
GstPad *srcpad, *sinkpad;
+ GstPadTemplate *templ;
GST_DEBUG_OBJECT (element, "setting up receiving pad");
/* receiving pad */
- sinkpad =
- gst_pad_new_from_template (gst_static_pad_template_get (template),
- "sink");
+ templ = gst_static_pad_template_get (template);
+ sinkpad = gst_pad_new_from_template (templ, "sink");
+ gst_object_unref (templ);
+
fail_if (sinkpad == NULL, "Could not create a sinkpad");
srcpad = gst_element_get_pad (element, "src");
gst_object_unref (mux->collect);
gst_object_unref (mux->ebml_write);
+ if (mux->writing_app)
+ g_free (mux->writing_app);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/* reset writing_app */
if (mux->writing_app) {
- free (mux->writing_app);
+ g_free (mux->writing_app);
}
mux->writing_app = g_strdup ("GStreamer Matroska muxer");
offset += GST_BUFFER_SIZE (buf[i]);
}
- if (memcmp (GST_BUFFER_DATA (buf[0]) + 1, "vorbis", 6) == 0) {
- guint8 *hdr = GST_BUFFER_DATA (buf[0]) + 1 + 6 + 4;
+ if (GST_BUFFER_SIZE (buf[0]) < 1 + 6 + 4) {
+ GST_WARNING ("First vorbis header too small, ignoring");
+ } else {
+ if (memcmp (GST_BUFFER_DATA (buf[0]) + 1, "vorbis", 6) == 0) {
+ guint8 *hdr = GST_BUFFER_DATA (buf[0]) + 1 + 6 + 4;
- audiocontext->channels = GST_READ_UINT8 (hdr);
- audiocontext->samplerate = GST_READ_UINT32_LE (hdr + 1);
+ audiocontext->channels = GST_READ_UINT8 (hdr);
+ audiocontext->samplerate = GST_READ_UINT32_LE (hdr + 1);
+ }
}
} else {
GST_WARNING ("Vorbis header does not contain "
g_free (rand);
gst_ebml_write_binary (ebml, GST_MATROSKA_ID_SEGMENTUID,
(guint8 *) segment_uid, 16);
+ g_free (segment_uid);
gst_ebml_write_uint (ebml, GST_MATROSKA_ID_TIMECODESCALE, mux->time_scale);
mux->duration_pos = ebml->pos;
/* get duration */
/* Query the total length of the track. */
peerpad = gst_pad_get_peer (thepad);
- GST_DEBUG ("Querying duration on pad %s:%s", GST_DEBUG_PAD_NAME (thepad));
+ GST_DEBUG_OBJECT (thepad, "querying duration");
if (gst_pad_query_duration (peerpad, &format, &trackduration)) {
- GST_DEBUG ("%s:%s - duration: %" GST_TIME_FORMAT,
- GST_DEBUG_PAD_NAME (thepad), GST_TIME_ARGS (trackduration));
+ GST_DEBUG_OBJECT (thepad, "%duration: %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (trackduration));
if ((gdouble) trackduration > duration) {
duration = (gdouble) trackduration;
}
/* if there is no best pad, we have reached EOS */
if (best == NULL) {
- GST_DEBUG ("No best pad finishing...");
+ GST_DEBUG_OBJECT (mux, "No best pad finishing...");
gst_matroska_mux_finish (mux);
gst_pad_push_event (mux->srcpad, gst_event_new_eos ());
return GST_FLOW_WRONG_STATE;
}
- GST_DEBUG ("Best pad %s.", gst_pad_get_name (best->collect.pad));
+ GST_DEBUG_OBJECT (best->collect.pad, "best pad");
/* write data */
buf = best->buffer;
{
GstMatroskaMux *mux = GST_MATROSKA_MUX (user_data);
- GST_DEBUG ("Collected pads");
+ GST_DEBUG_OBJECT (mux, "Collected pads");
/* start with a header */
if (mux->state == GST_MATROSKA_MUX_STATE_START) {
GstPad *
setup_src_pad (GstElement * element,
- GstStaticPadTemplate * srctemplate, GstCaps * caps)
+ GstStaticPadTemplate * template, GstCaps * caps)
{
GstPad *srcpad, *sinkpad;
+ GstPadTemplate *templ;
GST_DEBUG_OBJECT (element, "setting up sending pad");
/* sending pad */
- srcpad =
- gst_pad_new_from_template (gst_static_pad_template_get (srctemplate),
- "src");
+ templ = gst_static_pad_template_get (template);
+ srcpad = gst_pad_new_from_template (templ, "src");
+ gst_object_unref (templ);
fail_if (srcpad == NULL, "Could not create a srcpad");
ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
GstCaps * caps)
{
GstPad *srcpad, *sinkpad;
+ GstPadTemplate *templ;
GST_DEBUG_OBJECT (element, "setting up receiving pad");
/* receiving pad */
- sinkpad =
- gst_pad_new_from_template (gst_static_pad_template_get (template),
- "sink");
+ templ = gst_static_pad_template_get (template);
+ sinkpad = gst_pad_new_from_template (templ, "sink");
+ gst_object_unref (templ);
+
fail_if (sinkpad == NULL, "Could not create a sinkpad");
srcpad = gst_element_get_pad (element, "src");