Memory leak in playbin when resetting URI on about-to-finish signal
Describe your issue
I'm using the 'about-to-finish' signal to reset the playbin's URI to create an infinite loop. The memory usage of that program increases over time.
Here's the code:
// gs_loop_minimal_reset_uri.cpp
#include <gst/gst.h>
#include <iostream>
static void about_to_finish(GstElement* playbin, gpointer user_data)
{
auto uri = static_cast<char*>(user_data);
std::cout << "Bin about to finish, re-looping (reset uri): " << uri << std::endl;
g_object_set(G_OBJECT(playbin), "uri", uri, NULL);
}
int main(int argc, char *argv[])
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " <URI>" << std::endl;
return 1;
}
gst_init(NULL, NULL);
auto playbin = gst_element_factory_make("playbin", "myplaybin");
g_object_set(G_OBJECT(playbin), "uri", argv[1], NULL);
g_signal_connect(playbin, "about-to-finish", G_CALLBACK(about_to_finish), argv[1]);
if (gst_element_set_state(GST_ELEMENT(playbin), GST_STATE_PLAYING) == 0)
{
std::cerr << "Could not set state to playing for " << argv[1] << std::endl;
return 1;
}
std::cout << "Playback of " << argv[1] << " started." << std::endl;
auto main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (main_loop);
g_main_loop_unref (main_loop);
gst_object_unref(playbin);
gst_deinit();
return 0;
}
Expected Behavior
Memory usage remains stable.
Observed Behavior
Memory usage increases over time.
Setup
- Operating System: Ubuntu 20.04
- Device: Computer
- GStreamer Version: libgstreamer-plugins-base1.0-dev 1.16.3-0ubuntu1.2, libgstreamer1.0-dev 1.16.3-0ubuntu1.1
- Command line: gs_loop_minimal_reset_uri 2s.wav # (using source above)
Steps to reproduce the bug
- create
/tmp/gs_loop_minimal_reset_uri.cpp
with content from above - open terminal in
/tmp
g++ gs_loop_minimal_reset_uri.cpp -o gs_loop_minimal_reset_uri `pkg-config --cflags --libs gstreamer-1.0`
timeout 300 valgrind --tool=massif ./gs_loop_minimal_reset_uri file:///path/to/my/audio.wav # use any short wav file
massif-visualizer massif.out.*
How reproducible is the bug?
Always
Screenshots if relevant
Here's a massif-visualizer plot of a 5min playback of a 2s WAV file, created with valgrind --tool=massif ...
as described above: