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 784302 - v4l2allocator leak when dmabuf creation fails
v4l2allocator leak when dmabuf creation fails
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
1.8.3
Other Linux
: Normal normal
: 1.13.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-06-28 18:35 UTC by Matt Fischer
Modified: 2017-06-28 21:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix memory leak in dmabuf allocation (804 bytes, patch)
2017-06-28 19:29 UTC, Matt Fischer
none Details | Review
Fix memory leak in dmabuf allocation (1.19 KB, patch)
2017-06-28 19:54 UTC, Matt Fischer
committed Details | Review

Description Matt Fischer 2017-06-28 18:35:11 UTC
When the v4l2allocator allocates a dmabuf, I'm observing what appears to be a memory leak when the dmabuf creation process fails.  Specifically, when duplicating the dmabuf file descriptor fails (i.e. control passes to the dup_failed: label in gst_v4l2_allocator_alloc_dmabuf()), the allocator itself has an extra reference placed on it which is never removed, resulting in the allocator later failing to be cleaned up when the pipeline shuts down.

I was able to resolve the issue by placing a call to gst_object_unref (allocator) in the dup_failed block.  However, I am not positive that this is the correct fix, as I'm having some trouble understanding the refcounting semantics of the allocator through all of the GstMemory gymnastics that are taking place here.  I'm also unclear whether the expbuf_failed case would need the same fix, in which case the unref should go in the cleanup: label or even in the _cleanup_failed_alloc() function.  Can someone advise on exactly what the correct solution to this issue would be?
Comment 1 Nicolas Dufresne (ndufresne) 2017-06-28 19:23:51 UTC
Could you share what you did, might be better to understand what you tried.
Comment 2 Matt Fischer 2017-06-28 19:29:49 UTC
Created attachment 354643 [details] [review]
Fix memory leak in dmabuf allocation

Sure.  Here's what I tried, and it seems to resolve the error.  But I'm confused about how the refcounting works in here, so I'm not sure if this is the right place to fix it or not.
Comment 3 Nicolas Dufresne (ndufresne) 2017-06-28 19:41:48 UTC
Review of attachment 354643 [details] [review]:

::: sys/v4l2/gstv4l2allocator.c
@@ +922,3 @@
 cleanup:
   {
+    gst_object_unref (allocator);

I'm not sure if it's fully correct, the leak is in fact cause by the fact the we leave before we increment mems_allocated. I think the right solution is just to move "group->mems_allocated++;" right after:

>      /* Take back the allocator reference */
>      gst_object_ref (allocator);
>    }

-> HERE

Would you mind testing it ? Otherwise you also leak the GstMemory object.
Comment 4 Matt Fischer 2017-06-28 19:54:07 UTC
Created attachment 354646 [details] [review]
Fix memory leak in dmabuf allocation

I nearly suggested that originally, but wasn't sure if that would cause some kind of other consequences.  That does appear to fix the issue for me, so here's an updated patch.
Comment 5 Nicolas Dufresne (ndufresne) 2017-06-28 21:04:07 UTC
Thanks. This was pushed in master as e8a46787388ae7e1ee037304fd984758d39f1627.
It's a good candiate for backport, though I'll give it some more testing myself
before.