[gst-devel] memory leak

Antoine Tarault antoine.tarault at gmail.com
Fri Nov 16 10:12:05 CET 2007


Hi,

I would like to run a pipeline several times in a program. The problem is
that when a pipeline ends, and even if I free it with gst_object_unref, a
part of the memory is not freed.
Above is the really simple code I use to test this memory leak problem.

Thank you for your help,
Antoine Tarault


#include <gst/gst.h>

void gstMain()
{
 GstClock *clock;
 GstClockID clock_id;
 GstClockReturn wait_ret;
 GstElement *pipeline = NULL;
 GstElement *video_src = NULL;
 GstElement *video_sink = NULL;
 gboolean res;

 gst_init(NULL, NULL);


 pipeline = gst_pipeline_new("avd_pipeline");

 video_src = gst_element_factory_make("videotestsrc", "filesrc_avi");
 if (video_src == NULL)
 {
  g_print("Error creating plugin type videotestsrc\n");
  return;
 }

 video_sink = gst_element_factory_make("directdrawsink", "video_sink");
 if (video_sink == NULL)
 {
  g_print("Error creating plugin type directdrawsink\n");
  return;
 }

 gst_bin_add_many( GST_BIN(pipeline),
      video_src,
      video_sink,
      NULL);

 res = gst_element_link(video_src,video_sink);
 if(!res)
 {
  g_print("error linking video src to video sink");
  return;
 }

 clock = gst_pipeline_get_clock (GST_PIPELINE (pipeline));
 if(pipeline == NULL)
 {
  fprintf (stderr, "FREEING pipeline ...\n");
  gst_object_unref(pipeline);
  return;
 }

 clock_id =
      gst_clock_new_single_shot_id (clock,
      gst_clock_get_time (clock) + (7 * GST_SECOND));
 gst_object_unref(clock);

 if (gst_element_set_state (pipeline, GST_STATE_PLAYING)) {
  if ((wait_ret = gst_clock_id_wait (clock_id, NULL)) != GST_CLOCK_OK)
  {
   GST_WARNING ("clock_id_wait returned: %d", wait_ret);
  }
  fprintf (stderr, "Setting pipeline to NULL ...\n");
  gst_element_set_state(pipeline, GST_STATE_NULL);

  fprintf (stderr, "FREEING pipeline ...\n");
  gst_object_unref(pipeline);
 }
 return;
}


int main()
{
 gstMain();
 g_usleep(1000000);
 gstMain();
 return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20071116/bf72d39f/attachment.htm>


More information about the gstreamer-devel mailing list