ext/lame/gstlame.c: don't pass an uninitialised string pointer to lame if we don...
authorTim-Philipp Müller <tim@centricular.net>
Mon, 23 Jan 2006 15:02:04 +0000 (15:02 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Mon, 23 Jan 2006 15:02:04 +0000 (15:02 +0000)
Original commit message from CVS:
* ext/lame/gstlame.c: (add_one_tag):
Fix handling of GST_TAG_DATE (#311679), don't pass an
uninitialised string pointer to lame if we don't know
how to handle the tag type, and fix minor memory leak.

ChangeLog
ext/lame/gstlame.c

index 9816245fbdf57cbbde6ea8486609c86a6d92a6f4..2fdb74f22e15e9e910f2633342f4570e34a83e91 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-01-23  Tim-Philipp Müller  <tim at centricular dot net>
+
+       * ext/lame/gstlame.c: (add_one_tag):
+         Fix handling of GST_TAG_DATE (#311679), don't pass an
+         uninitialised string pointer to lame if we don't know
+         how to handle the tag type, and fix minor memory leak.
+
 2006-01-23  Tim-Philipp Müller  <tim at centricular dot net>
 
        * ext/mad/gstmad.c: (gst_mad_chain):
index fde95f5e15dabaf3ebe1e1140dbe7b8081697b94..c22f6349f79a73056fb1642c5c111e636997570c 100644 (file)
@@ -580,7 +580,7 @@ static void
 add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
 {
   GstLame *lame;
-  gchar *value;
+  gchar *value = NULL;
   int i = 0;
 
   lame = GST_LAME (user_data);
@@ -616,16 +616,29 @@ add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
         return;
       };
       break;
-    default:
-      GST_WARNING_OBJECT (lame, "Couldn't write tag %s", tag);
+    default:{
+      if (strcmp (tag, GST_TAG_DATE) == 0) {
+        GDate *date = NULL;
+
+        if (!gst_tag_list_get_date (list, tag, &date) || date == NULL) {
+          GST_WARNING_OBJECT (lame, "Error reading \"%s\" tag value", tag);
+        } else {
+          value = g_strdup_printf ("%u", g_date_get_year (date));
+          g_date_free (date);
+        }
+      } else {
+        GST_WARNING_OBJECT (lame, "Couldn't write tag %s", tag);
+      }
       break;
+    }
   }
 
-  tag_matches[i].tag_func (lame->lgf, value);
-
-  if (gst_tag_get_type (tag) == G_TYPE_UINT) {
-    g_free (value);
+  if (value != NULL && *value != '\0') {
+    GST_LOG_OBJECT (lame, "Adding tag %s:%s", tag, value);
+    tag_matches[i].tag_func (lame->lgf, value);
   }
+
+  g_free (value);
 }
 
 static void