GNOME Bugzilla – Bug 765005
mpegtsmux: memory leak caused by pad_data->language
Last modified: 2016-04-15 20:18:55 UTC
I noticed small memory leak caused by pad_data->language in mpegtsmux in the following line: GST_DEBUG_OBJECT (pad, "Setting language to '%s'", lang_code); pad_data->language = g_strdup (lang_code); I added to WARNING messages to confirm that g_strdup is invoked more times that g_free(pad_data->language) in the following places: 1) - GST_DEBUG_OBJECT (pad, "Setting language to '%s'", lang_code); + GST_WARNING_OBJECT (pad, "Setting language to '%s'", lang_code); pad_data->language = g_strdup (lang_code); 2) if (pad_data->language) { + GST_WARNING(releasing pad_data->language); g_free (pad_data->language); pad_data->language = NULL; } And got following output in logs: 0:00:10.753865376 9671 0x9cd96c0 WARN mpegtsmux mpegtsmux.c:356:mpegtsmux_pad_reset: releasing pad_data->language 0:00:10.755888141 9671 0x9cd96c0 WARN mpegtsmux mpegtsmux.c:869:mpegtsmux_sink_event <splitmuxsink_rabbitmq_mpegtsmux_4287:sink_66> Setting language to 'eng' 0:00:10.775769785 9671 0x9cd96c0 WARN mpegtsmux mpegtsmux.c:869:mpegtsmux_sink_event:<splitmuxsink_rabbitmq_mpegtsmux_4287:sink_66> Setting language to 'eng' 0:00:11.211465160 9671 0x9b7e1b0 WARN mpegtsmux mpegtsmux.c:356:mpegtsmux_pad_reset: releasing pad_data->language 0:00:11.213284822 9671 0x9b7e1b0 WARN mpegtsmux mpegtsmux.c:869:mpegtsmux_sink_event:<splitmuxsink_rabbitmq_mpegtsmux_4352:sink_66> Setting language to 'eng' 0:00:11.220769453 9671 0x9b7fb80 WARN mpegtsmux mpegtsmux.c:869:mpegtsmux_sink_event:<splitmuxsink_rabbitmq_mpegtsmux_4352:sink_66> Setting language to 'eng' 0:00:11.408445647 9671 0x9ce37b0 WARN mpegtsmux mpegtsmux.c:356:mpegtsmux_pad_reset: releasing pad_data->language 0:00:11.411094371 9671 0x9ce37b0 WARN mpegtsmux mpegtsmux.c:869:mpegtsmux_sink_event:<splitmuxsink_rabbitmq_mpegtsmux_4170:sink_66> Setting language to 'eng' 0:00:11.428846042 9671 0x9ce37b0 WARN mpegtsmux mpegtsmux.c:869:mpegtsmux_sink_event:<splitmuxsink_rabbitmq_mpegtsmux_4170:sink_66> Setting language to 'eng' 0:00:11.622453320 9671 0x9b04150 WARN mpegtsmux mpegtsmux.c:356:mpegtsmux_pad_reset: releasing pad_data->language 0:00:11.624472643 9671 0x9b04150 WARN mpegtsmux mpegtsmux.c:869:mpegtsmux_sink_event:<splitmuxsink_rabbitmq_mpegtsmux_4736:sink_66> Setting language to 'eng' 0:00:11.641586594 9671 0x9b04150 WARN mpegtsmux mpegtsmux.c:869:mpegtsmux_sink_event:<splitmuxsink_rabbitmq_mpegtsmux_4736:sink_66> Setting language to 'eng' 0:00:11.711140623 9671 0x9cd96c0 WARN mpegtsmux mpegtsmux.c:356:mpegtsmux_pad_reset: releasing pad_data->language 0:00:11.712432191 9671 0x9cd96c0 WARN mpegtsmux mpegtsmux.c:869:mpegtsmux_sink_event:<splitmuxsink_rabbitmq_mpegtsmux_4287:sink_66> Setting language to 'eng' 0:00:11.736278444 9671 0x9cd96c0 WARN mpegtsmux mpegtsmux.c:869:mpegtsmux_sink_event:<splitmuxsink_rabbitmq_mpegtsmux_4287:sink_66> Setting language to 'eng' 0:00:12.003196165 9671 0x9ce37b0 WARN mpegtsmux mpegtsmux.c:356:mpegtsmux_pad_reset: releasing pad_data->language 0:00:12.004533775 9671 0x9ce37b0 WARN mpegtsmux mpegtsmux.c:869:mpegtsmux_sink_event:<splitmuxsink_rabbitmq_mpegtsmux_4170:sink_66> Setting language to 'eng' 0:00:12.021611624 9671 0x9ce37b0 WARN mpegtsmux mpegtsmux.c:869:mpegtsmux_sink_event:<splitmuxsink_rabbitmq_mpegtsmux_4170:sink_66> Setting language to 'eng' We can see that for each invokation of releasing pad_data->language, we have 2 invokations of g_strdup() - which causes memory leak.
Created attachment 325875 [details] [review] Solving memory leak in mpegtsmux by freeing pad_data->language before g_strdup Attached patch solves this memory leak for me.
I reopend this ticket as I don't know whether I should set it to RESOLVED after applying patch. Please let me know.
Thanks for the patch. You should not close the bug or change the patch status, a GStreamer developer will do that once they have applied the patch to the GStreamer repository.
Created attachment 325878 [details] [review] Solving memory leak in mpegtsmux by freeing pad_data->language before g_strdup - new
Thanks for the patch! commit 6141cd2f4b2f3ed91b206e5430c0acf666bb800b Author: Damian Ziobro <damian@xmementoit.com> Date: Wed Apr 13 18:12:25 2016 +0100 mpegtsmux: free pad_data->language before g_strdup in order to avoid memory leak https://bugzilla.gnome.org/show_bug.cgi?id=765005
For future reference, you don't need to check if a variable != NULL before calling g_free. g_free just returns if you pass it NULL, and you don't need to then set the variable to NULL before then assigning a new value from g_strdup :)
Hi Jan, Thanks for your suggestions. Good to find out it. Actually, I just use if statement as was implemented in mpegtsmux_pad_reset() function. However I will remember for the future.