[gst-cvs] gst-plugins-good: v4l2src: fix memory leak in new uri handler code

Tim Mueller tpm at kemper.freedesktop.org
Tue Jan 5 01:54:42 PST 2010


Module: gst-plugins-good
Branch: master
Commit: d68689255df0de08a9ff6fe7366c3d1aeed1380e
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-good/commit/?id=d68689255df0de08a9ff6fe7366c3d1aeed1380e

Author: Tim-Philipp Müller <tim.muller at collabora.co.uk>
Date:   Tue Jan  5 09:47:00 2010 +0000

v4l2src: fix memory leak in new uri handler code

Don't leak a string everytime get_uri() is called and a device
has been set. There's a limited number of devices, so just
intern the string instead of doing more elaborate housekeeping
and storing it in the instance struct or so.

---

 sys/v4l2/gstv4l2src.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/sys/v4l2/gstv4l2src.c b/sys/v4l2/gstv4l2src.c
index ed94626..7dd7737 100644
--- a/sys/v4l2/gstv4l2src.c
+++ b/sys/v4l2/gstv4l2src.c
@@ -982,8 +982,16 @@ gst_v4l2src_uri_get_uri (GstURIHandler * handler)
 {
   GstV4l2Src *v4l2src = GST_V4L2SRC (handler);
 
-  if (v4l2src->v4l2object->videodev)
-    return g_strdup_printf ("v4l2://%s", v4l2src->v4l2object->videodev);
+  if (v4l2src->v4l2object->videodev != NULL) {
+    gchar uri[256];
+
+    /* need to return a const string, but also don't want to leak the generated
+     * string, so just intern it - there's a limited number of video devices
+     * after all */
+    g_snprintf (uri, sizeof (uri), "v4l2://%s", v4l2src->v4l2object->videodev);
+    return g_intern_string (uri);
+  }
+
   return "v4l2://";
 }
 





More information about the Gstreamer-commits mailing list