After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 732789 - mpegts: don't confuse slice allocator with regular allocator
mpegts: don't confuse slice allocator with regular allocator
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other All
: Normal normal
: 1.3.91
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-07-05 23:59 UTC by Sebastian Rasmussen
Modified: 2014-07-11 08:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch 1/2. (1.94 KB, patch)
2014-07-06 00:00 UTC, Sebastian Rasmussen
reviewed Details | Review
Proposed patch 2/2. (3.39 KB, patch)
2014-07-06 00:00 UTC, Sebastian Rasmussen
none Details | Review
Proposed patch 3/2. (2.95 KB, patch)
2014-07-06 00:14 UTC, Sebastian Rasmussen
none Details | Review
Proposed patch 1/2. (2.22 KB, patch)
2014-07-06 23:28 UTC, Sebastian Rasmussen
none Details | Review
Proposed patch 1/2. (2.27 KB, patch)
2014-07-09 07:47 UTC, Sebastian Rasmussen
committed Details | Review
Proposed patch 2/2. (3.39 KB, patch)
2014-07-09 07:48 UTC, Sebastian Rasmussen
committed Details | Review

Description Sebastian Rasmussen 2014-07-05 23:59:29 UTC
The first patch fixes Coverity defect id 1224131.
The second patch is hopefully an uncontroversial cleanup.
Comment 1 Sebastian Rasmussen 2014-07-06 00:00:14 UTC
Created attachment 279969 [details] [review]
Proposed patch 1/2.
Comment 2 Sebastian Rasmussen 2014-07-06 00:00:27 UTC
Created attachment 279970 [details] [review]
Proposed patch 2/2.
Comment 3 Sebastian Rasmussen 2014-07-06 00:14:34 UTC
Created attachment 279971 [details] [review]
Proposed patch 3/2.

Stumbled on Coverity defect id 1224130 as well in the same area with the same kind of problem.
Comment 4 Tim-Philipp Müller 2014-07-06 21:49:12 UTC
Comment on attachment 279969 [details] [review]
Proposed patch 1/2.

>@@ -977,7 +977,7 @@ _gst_mpegts_extended_event_descriptor_copy (GstMpegtsExtendedEventDescriptor *
> 
>   copy = g_slice_dup (GstMpegtsExtendedEventDescriptor, source);
>   copy->items = g_ptr_array_ref (source->items);
>-  copy->text = g_slice_copy (sizeof (source->text), source->text);
>+  copy->text = g_memdup (source->text, strlen (source->text));

g_strdup() please.

>@@ -1870,7 +1870,7 @@ void
> gst_mpegts_dvb_data_broadcast_descriptor_free (GstMpegtsDataBroadcastDescriptor
>     * source)
> {
>-  g_free (source->selector_bytes);
>+  g_slice_free1 (source->length, source->selector_bytes);
>   g_free (source->language_code);
>   g_free (source->text);
>   g_slice_free (GstMpegtsDataBroadcastDescriptor, source);
>@@ -1913,7 +1913,7 @@ gst_mpegts_descriptor_parse_dvb_data_broadcast (const GstMpegtsDescriptor
>   res->length = *data;
>   data += 1;
> 
>-  res->selector_bytes = g_memdup (data, res->length);
>+  res->selector_bytes = g_slice_copy (res->length, data);
>   data += res->length;

I think here the g_slice_copy() should be changed to g_memdup() and these two should be left alone. Generally I don't think we should use GSlice for random chunks of memory, only structs or if we know that often chunks of the same size are going to be allocated.
Comment 5 Sebastian Rasmussen 2014-07-06 21:52:05 UTC
> Generally I don't think we should use GSlice for randomchunks of memory, only
> structs or if we know that often chunks of the same size are going to be
> allocated.

Alright, I opted to keep as much of the original code as possible. Was a bit unclear what direction to take. I'll fix the patch ASAP.
Comment 6 Sebastian Rasmussen 2014-07-06 23:28:53 UTC
Created attachment 280014 [details] [review]
Proposed patch 1/2.

Fixed Tim's review comments.
Comment 7 Edward Hervey 2014-07-09 05:53:16 UTC
Sebastian, can you rebase against current master ? I only just realized this bug was open, and pushed a fix for one of the leaks. We should get those leak fixes in before 1.4.0.
Comment 8 Sebastian Rasmussen 2014-07-09 06:39:11 UTC
> Sebastian, can you rebase against current master ? 

Of course. Let me just ask -- private_data_length is after your patch allocated by the slice allocator (this is where our patches conflict). It seems to me that this datastructure is of variable size like __tim mentioned above which leads me to believe that using the normal allocator is more appropriate? If you want me to I keep that part of the change because of this reason? Let me know and I'll rebase and upload again.
Comment 9 Edward Hervey 2014-07-09 07:29:22 UTC
Yes, it should be switched to the regular allocator.
Comment 10 Sebastian Rasmussen 2014-07-09 07:47:52 UTC
Created attachment 280209 [details] [review]
Proposed patch 1/2.
Comment 11 Sebastian Rasmussen 2014-07-09 07:48:11 UTC
Created attachment 280210 [details] [review]
Proposed patch 2/2.
Comment 12 Sebastian Rasmussen 2014-07-09 07:49:28 UTC
> Yes, it should be switched to the regular allocator.

Alright, I think I rebased everything successfully now.
Comment 13 Edward Hervey 2014-07-09 15:33:16 UTC
commit fba6ebaae2d9adb5aa501fc81b4a7005042f71c6
Author: Sebastian Rasmussen <sebras@hotmail.com>
Date:   Sun Jul 6 01:55:50 2014 +0200

    mpegts: No need to check for NULL before calling g_free()
    
    Fixes https://bugzilla.gnome.org/show_bug.cgi?id=732789

commit 66c38b50f3ddd911eb5abd05e8095e438cadec78
Author: Sebastian Rasmussen <sebras@hotmail.com>
Date:   Sun Jul 6 01:55:16 2014 +0200

    mpegts: Don't confuse slice allocator with regular one
    
    Previously selector_bytes and private_data_bytes were sometimes allocated and
    free using the normal allocator and sometimes using the slice allocator.
    Additionally prefer g_strdup() to g_memdup() for strings.
    
    Fixes https://bugzilla.gnome.org/show_bug.cgi?id=732789