diff --git a/ChangeLog b/ChangeLog index 8a1afc3504..67feedb171 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-03-17 Tim-Philipp Müller + + * gst/gstindex.c: (gst_index_entry_free): + * gst/gstindex.h: + Don't free key strings which we don't own. Fixes crash in + gst_index_entry_free() (#522741). + + * tests/check/Makefile.am: + * tests/check/gst/.cvsignore: + * tests/check/gst/gstindex.c: (test_index_entries), + (gst_index_suite), (gst_index): + Add unit test for the above. + 2008-03-11 Sebastian Dröge * win32/common/libgstreamer.def: diff --git a/gst/gstindex.c b/gst/gstindex.c index eb12397651..251beb0b2a 100644 --- a/gst/gstindex.c +++ b/gst/gstindex.c @@ -545,16 +545,8 @@ gst_index_entry_free (GstIndexEntry * entry) } break; case GST_INDEX_ENTRY_OBJECT: - if (entry->data.object.key) { - g_free (entry->data.object.key); - entry->data.object.key = NULL; - } break; case GST_INDEX_ENTRY_FORMAT: - if (entry->data.format.key) { - g_free (entry->data.format.key); - entry->data.format.key = NULL; - } break; } diff --git a/gst/gstindex.h b/gst/gstindex.h index 6ce477a219..99f5452d6f 100644 --- a/gst/gstindex.h +++ b/gst/gstindex.h @@ -214,7 +214,7 @@ struct _GstIndexEntry { } object; struct { GstFormat format; - gchar *key; + const gchar *key; } format; } data; }; diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index bcc652322d..2a08bf7c49 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -49,6 +49,7 @@ REGISTRY_CHECKS = \ gst/gstelement \ gst/gstevent \ gst/gstghostpad \ + gst/gstindex \ gst/gstinterface \ gst/gstplugin \ gst/gstquery \ diff --git a/tests/check/gst/.gitignore b/tests/check/gst/.gitignore index 2a93de752f..85f72f4e7b 100644 --- a/tests/check/gst/.gitignore +++ b/tests/check/gst/.gitignore @@ -10,6 +10,7 @@ gstelement gstevent gstghostpad gstiterator +gstindex gstinterface gstmessage gstminiobject diff --git a/tests/check/gst/gstindex.c b/tests/check/gst/gstindex.c new file mode 100644 index 0000000000..f533dd07e8 --- /dev/null +++ b/tests/check/gst/gstindex.c @@ -0,0 +1,59 @@ +/* GStreamer GstIndex unit test + * Copyright (C) 2008 Tim-Philipp Müller + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +#include +#include + +GST_START_TEST (test_index_entries) +{ + GstIndexEntry *entry; + GstElement *pipe; + GstIndex *index; + gint id = -1; + + pipe = gst_pipeline_new ("pipeline"); + + index = gst_index_new (); + fail_unless (gst_index_get_writer_id (index, GST_OBJECT (pipe), &id)); + + entry = gst_index_add_format (index, id, GST_FORMAT_BYTES); + gst_index_entry_free (entry); + + gst_object_unref (index); + gst_object_unref (pipe); + +} + +GST_END_TEST; + +static Suite * +gst_index_suite (void) +{ + Suite *s = suite_create ("GstIndex"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_index_entries); + + return s; +} + +GST_CHECK_MAIN (gst_index);