mpegts: Fix memory leaks in the test and the library
authorSebastian Dröge <sebastian@centricular.com>
Sun, 29 Jun 2014 19:34:50 +0000 (21:34 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Sun, 29 Jun 2014 19:34:50 +0000 (21:34 +0200)
Currently uses g_boxed_free() in the unit test, this needs to
be fixed properly when cleaning up the API.

https://bugzilla.gnome.org/show_bug.cgi?id=730914

gst-libs/gst/mpegts/gst-atsc-section.c
gst-libs/gst/mpegts/gst-dvb-descriptor.c
tests/check/libs/mpegts.c

index cff1d1809d23707b8b9b65389b375bfd792fa3e8..fe97cada2626c4f1732eb09f3cf8bf82bcff5641 100644 (file)
@@ -842,6 +842,9 @@ _gst_mpegts_atsc_stt_free (GstMpegtsAtscSTT * stt)
 {
   if (stt->descriptors)
     g_ptr_array_unref (stt->descriptors);
+  if (stt->utc_datetime)
+    gst_date_time_unref (stt->utc_datetime);
+
   g_slice_free (GstMpegtsAtscSTT, stt);
 }
 
index 9793de516aaee97435bd43f8c837bb0deadd5556..9bf6629fa0bbb323358824932ef68e2accbe31d0 100644 (file)
@@ -97,7 +97,10 @@ gst_mpegts_descriptor_from_dvb_network_name (const gchar * name)
 
   converted_name = dvb_text_from_utf8 (name, &size);
 
-  g_return_val_if_fail (size < 256, NULL);
+  if (size >= 256) {
+    g_free (converted_name);
+    return NULL;
+  }
 
   if (!converted_name) {
     GST_WARNING ("Could not find proper encoding for string `%s`", name);
index f5bc84b189ea21aa928cb2504fc4330137c68b65..f22c6e35875add12a97fbd04e1e7f49ae5d54938 100644 (file)
@@ -78,7 +78,7 @@ GST_START_TEST (test_mpegts_pat)
   gsize data_size;
 
   /* Check creation of PAT */
-  pat = g_ptr_array_new ();
+  pat = gst_mpegts_pat_new ();
 
   for (i = 0; i < 2; i++) {
     program = gst_mpegts_pat_program_new ();
@@ -103,6 +103,8 @@ GST_START_TEST (test_mpegts_pat)
     assert_equals_int (program->program_number, i);
     assert_equals_int (program->network_or_program_map_PID, 0x30 + i);
   }
+  g_ptr_array_unref (pat);
+  pat = NULL;
 
   /* Packetize the section, and check the data integrity */
   data = gst_mpegts_section_packetize (pat_section, &data_size);
@@ -116,13 +118,13 @@ GST_START_TEST (test_mpegts_pat)
 
   /* Check assertion on bad CRC. Reset parsed data, and make the CRC corrupt */
   pat_section->data[pat_section->section_length - 1]++;
+  pat_section->destroy_parsed (pat_section->cached_parsed);
   pat_section->cached_parsed = NULL;
-  pat = gst_mpegts_section_get_pat (pat_section);
 
+  pat = gst_mpegts_section_get_pat (pat_section);
   fail_unless (pat == NULL);
 
   gst_mpegts_section_unref (pat_section);
-
 }
 
 GST_END_TEST;
@@ -197,6 +199,7 @@ GST_START_TEST (test_mpegts_pmt)
 
   /* Check assertion on bad CRC. Reset parsed data, and make the CRC corrupt */
   pmt_section->data[pmt_section->section_length - 1]++;
+  pmt_section->destroy_parsed (pmt_section->cached_parsed);
   pmt_section->cached_parsed = NULL;
   pmt = (GstMpegtsPMT *) gst_mpegts_section_get_pmt (pmt_section);
 
@@ -261,6 +264,8 @@ GST_START_TEST (test_mpegts_nit)
   fail_unless (gst_mpegts_descriptor_parse_dvb_network_name (desc,
           &name) == TRUE);
 
+  g_free (name);
+
   for (i = 0; i < 2; i++) {
     stream = g_ptr_array_index (nit->streams, i);
 
@@ -274,6 +279,7 @@ GST_START_TEST (test_mpegts_nit)
 
     fail_unless (gst_mpegts_descriptor_parse_dvb_network_name (desc,
             &name) == TRUE);
+    g_free (name);
   }
 
   /* Packetize the section, and check data integrity */
@@ -289,6 +295,7 @@ GST_START_TEST (test_mpegts_nit)
 
   /* Check assertion on bad CRC. Reset parsed data, and make the CRC corrupt */
   nit_section->data[nit_section->section_length - 1]++;
+  nit_section->destroy_parsed (nit_section->cached_parsed);
   nit_section->cached_parsed = NULL;
   nit = (GstMpegtsNIT *) gst_mpegts_section_get_nit (nit_section);
 
@@ -377,6 +384,7 @@ GST_START_TEST (test_mpegts_sdt)
 
   /* Check assertion on bad CRC. Reset parsed data, and make the CRC corrupt */
   sdt_section->data[sdt_section->section_length - 1]++;
+  sdt_section->destroy_parsed (sdt_section->cached_parsed);
   sdt_section->cached_parsed = NULL;
   sdt = (GstMpegtsSDT *) gst_mpegts_section_get_sdt (sdt_section);
 
@@ -445,6 +453,7 @@ GST_START_TEST (test_mpegts_descriptors)
       fail ("0x%X != 0x%X in byte %d of registration descriptor",
           desc->data[i], registration_descriptor[i], i);
   }
+  g_boxed_free (GST_TYPE_MPEGTS_DESCRIPTOR, desc);
 }
 
 GST_END_TEST;
@@ -488,11 +497,13 @@ GST_START_TEST (test_mpegts_dvb_descriptors)
   ret = gst_mpegts_descriptor_parse_dvb_network_name (desc, &string);
   fail_unless (ret == TRUE);
   fail_unless (strcmp (string, "Name") == 0);
+  g_free (string);
+  g_boxed_free (GST_TYPE_MPEGTS_DESCRIPTOR, desc);
 
   /* Descriptor should fail if string is more than 255 bytes */
   memset (long_string, 0x41, 256);
   long_string[256] = 0x00;
-  ASSERT_CRITICAL (gst_mpegts_descriptor_from_dvb_network_name (long_string));
+  fail_if (gst_mpegts_descriptor_from_dvb_network_name (long_string) != NULL);
 
   /*
    * Service descriptor (0x48)
@@ -518,6 +529,9 @@ GST_START_TEST (test_mpegts_dvb_descriptors)
   fail_unless (service_type == GST_DVB_SERVICE_DIGITAL_TELEVISION);
   fail_unless (strcmp (string, "Name") == 0);
   fail_unless (strcmp (provider, "Provider") == 0);
+  g_free (string);
+  g_free (provider);
+  g_boxed_free (GST_TYPE_MPEGTS_DESCRIPTOR, desc);
 
   /* Check creation of descriptor without data */
   desc = gst_mpegts_descriptor_from_dvb_service
@@ -529,6 +543,7 @@ GST_START_TEST (test_mpegts_dvb_descriptors)
   /* Check parsing of descriptor without data */
   ret = gst_mpegts_descriptor_parse_dvb_service (desc, NULL, NULL, NULL);
   fail_unless (ret == TRUE);
+  g_boxed_free (GST_TYPE_MPEGTS_DESCRIPTOR, desc);
 
   /* Descriptor should fail if string is more than 255 bytes */
   memset (long_string, 0x41, 256);