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 732734 - v4l2src: Seems to leak fd when camera is unplugged
v4l2src: Seems to leak fd when camera is unplugged
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
git master
Other other
: Normal normal
: 1.4.6
Assigned To: Nicolas Dufresne (ndufresne)
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-07-04 11:25 UTC by Lee Matthews
Modified: 2015-01-09 05:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Some Android native C code that reproduces the potential bug (6.01 KB, text/x-csrc)
2014-07-08 12:04 UTC, Lee Matthews
  Details
A text dump of 'ls -la /proc/PID/fd' after the code has finished executing (6.54 KB, text/plain)
2014-07-08 12:12 UTC, Lee Matthews
  Details
lsof output (2.81 KB, text/plain)
2014-08-21 20:13 UTC, Charles
  Details
GST_DEBUG output (131.50 KB, text/plain)
2014-08-21 20:23 UTC, Charles
  Details
v4l2bufferpool: Never fail on streamoff (3.02 KB, patch)
2015-01-08 16:43 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review

Description Lee Matthews 2014-07-04 11:25:38 UTC
I have some gstreamer code that accesses an external webcam attached to an Android mobile device.

The webcam normally gets mounted on /dev/video3. I then access the webcam using the v4l2src element. The problems appears if the webcam is unplugged whilst reading video data.

When the device is unplugged, I detect an error and close all the resources, ie set the pipeline to NULL and then unreference the pipeline.

If I plug the device back in, it is mounted as /dev/video4. If I repeat the above process, it is mounted as /dev/video5 and so on.

It is as though the device node is not being closed properly and Android is allocating the next free one. 

If I run ls -la /proc/4487/fd [4487 is my application's process id] each time I unplug/replug the camera, the number of files seems to be increasing, see logs below.

I downloaded and built the Android static cerbero tool. I obtained the "head" version from the repository on May the 30th 2014.

Lee
--

130|root@hammerhead:/ # ls -la /proc/4487/fd                                  
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 0 -> /dev/null
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 1 -> /dev/null
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 10 -> socket:[9230]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 11 -> /system/framework/okhttp.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 12 -> /system/framework/core-junit.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 13 -> /system/framework/bouncycastle.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 14 -> /system/framework/ext.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 15 -> /system/framework/framework.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 16 -> /system/framework/framework2.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 17 -> /system/framework/telephony-common.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 18 -> /system/framework/voip-common.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 19 -> /system/framework/mms-common.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 2 -> /dev/null
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 20 -> /system/framework/android.policy.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 21 -> /system/framework/services.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 22 -> /system/framework/apache-xml.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 23 -> /system/framework/webviewchromium.jar
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 24 -> /dev/log/main
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 25 -> /dev/log/radio
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 26 -> /dev/log/events
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 27 -> /dev/log/system
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 28 -> /system/framework/framework.jar
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 29 -> /sys/kernel/debug/tracing/trace_marker
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 3 -> /dev/log/main
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 30 -> /system/framework/framework-res.apk
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 31 -> /system/framework/core.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 32 -> socket:[9549]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 33 -> socket:[225213]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 34 -> /dev/cpuctl/apps/tasks
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 35 -> /dev/cpuctl/apps/bg_non_interactive/tasks
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 36 -> pipe:[225214]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 37 -> pipe:[225214]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 38 -> /dev/binder
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 39 -> pipe:[225217]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 4 -> /dev/log/radio
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 40 -> pipe:[225217]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 41 -> anon_inode:[eventpoll]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 42 -> /data/app/com.mobinet.mobinetbootapp-2.apk
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 43 -> /data/app/com.mobinet.mobinetbootapp-2.apk
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 44 -> socket:[225228]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 45 -> socket:[226446]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 46 -> socket:[226447]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 47 -> socket:[226448]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 48 -> /dev/kgsl-3d0
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 49 -> socket:[225556]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 5 -> /dev/log/events
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 50 -> socket:[225559]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 51 -> /dev/ion
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 52 -> /dev/video3
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 53 -> socket:[225229]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 54 -> anon_inodemabuf
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 55 -> anon_inodemabuf
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 56 -> /dev/ion
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 57 -> socket:[225235]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 58 -> anon_inodemabuf
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 59 -> anon_inodemabuf
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 6 -> /dev/log/system
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 60 -> socket:[226501]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 61 -> socket:[226502]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 62 -> socket:[225236]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 63 -> anon_inode:[eventfd]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 64 -> anon_inode:[eventfd]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 65 -> /dev/video3
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 66 -> socket:[226509]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 67 -> socket:[225241]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 68 -> socket:[225242]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 69 -> socket:[225243]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 7 -> /system/framework/core.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 70 -> socket:[225244]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 71 -> socket:[225245]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 72 -> socket:[225246]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 73 -> /dev/video3
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 74 -> socket:[225249]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 75 -> socket:[225250]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 76 -> socket:[225251]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 77 -> socket:[225252]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 78 -> /dev/video3
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 8 -> /system/framework/conscrypt.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 9 -> /dev/__properties__
root@hammerhead:/ #
root@hammerhead:/ #
root@hammerhead:/ #
root@hammerhead:/ #
root@hammerhead:/ #
root@hammerhead:/ # ls -la /proc/4487/fd                                      
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 0 -> /dev/null
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 1 -> /dev/null
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 10 -> socket:[9230]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 11 -> /system/framework/okhttp.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 12 -> /system/framework/core-junit.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 13 -> /system/framework/bouncycastle.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 14 -> /system/framework/ext.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 15 -> /system/framework/framework.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 16 -> /system/framework/framework2.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 17 -> /system/framework/telephony-common.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 18 -> /system/framework/voip-common.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 19 -> /system/framework/mms-common.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 2 -> /dev/null
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 20 -> /system/framework/android.policy.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 21 -> /system/framework/services.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 22 -> /system/framework/apache-xml.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 23 -> /system/framework/webviewchromium.jar
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 24 -> /dev/log/main
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 25 -> /dev/log/radio
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 26 -> /dev/log/events
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 27 -> /dev/log/system
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 28 -> /system/framework/framework.jar
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 29 -> /sys/kernel/debug/tracing/trace_marker
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 3 -> /dev/log/main
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 30 -> /system/framework/framework-res.apk
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 31 -> /system/framework/core.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 32 -> socket:[9549]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 33 -> socket:[225213]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 34 -> /dev/cpuctl/apps/tasks
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 35 -> /dev/cpuctl/apps/bg_non_interactive/tasks
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 36 -> pipe:[225214]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 37 -> pipe:[225214]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 38 -> /dev/binder
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 39 -> pipe:[225217]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 4 -> /dev/log/radio
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 40 -> pipe:[225217]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 41 -> anon_inode:[eventpoll]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 42 -> /data/app/com.mobinet.mobinetbootapp-2.apk
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 43 -> /data/app/com.mobinet.mobinetbootapp-2.apk
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 44 -> socket:[225228]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 45 -> socket:[226446]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 46 -> socket:[226447]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 47 -> socket:[226448]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 48 -> /dev/kgsl-3d0
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 49 -> socket:[225556]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 5 -> /dev/log/events
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 50 -> socket:[225559]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 51 -> /dev/ion
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 52 -> /dev/video3 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 53 -> socket:[225229]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 54 -> anon_inodemabuf
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 55 -> anon_inodemabuf
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 56 -> /dev/ion
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 57 -> socket:[225235]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 58 -> anon_inodemabuf
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 59 -> anon_inodemabuf
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 6 -> /dev/log/system
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 60 -> socket:[226501]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 61 -> socket:[226502]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 62 -> socket:[225236]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 63 -> anon_inode:[eventfd]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 64 -> /dev/video4
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 65 -> anon_inode:[eventfd]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 66 -> socket:[227519]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 67 -> socket:[227520]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 68 -> /dev/video4
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 69 -> socket:[225243]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 7 -> /system/framework/core.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 70 -> socket:[225244]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 71 -> socket:[225245]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 72 -> socket:[225246]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 73 -> /dev/video3 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 74 -> socket:[225249]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 75 -> socket:[225250]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 76 -> socket:[225251]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 77 -> socket:[225252]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 78 -> /dev/video3 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 79 -> socket:[227531]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 8 -> /system/framework/conscrypt.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 80 -> /dev/video4
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 81 -> socket:[227525]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 82 -> socket:[227526]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 83 -> socket:[227527]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 84 -> socket:[227528]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 85 -> socket:[227529]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 86 -> socket:[227530]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 87 -> socket:[227532]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 88 -> socket:[227533]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 89 -> socket:[227534]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 9 -> /dev/__properties__
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 90 -> socket:[227535]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 91 -> /dev/video4
root@hammerhead:/ #
root@hammerhead:/ #
root@hammerhead:/ #
root@hammerhead:/ # ls -la /proc/4487/fd                                      
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 0 -> /dev/null
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 1 -> /dev/null
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 10 -> socket:[9230]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 100 -> socket:[227680]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 101 -> socket:[227681]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 102 -> socket:[227682]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 103 -> socket:[227683]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 104 -> socket:[227684]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 105 -> socket:[227685]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 11 -> /system/framework/okhttp.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 12 -> /system/framework/core-junit.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 13 -> /system/framework/bouncycastle.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 14 -> /system/framework/ext.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 15 -> /system/framework/framework.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 16 -> /system/framework/framework2.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 17 -> /system/framework/telephony-common.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 18 -> /system/framework/voip-common.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 19 -> /system/framework/mms-common.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 2 -> /dev/null
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 20 -> /system/framework/android.policy.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 21 -> /system/framework/services.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 22 -> /system/framework/apache-xml.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 23 -> /system/framework/webviewchromium.jar
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 24 -> /dev/log/main
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 25 -> /dev/log/radio
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 26 -> /dev/log/events
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 27 -> /dev/log/system
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 28 -> /system/framework/framework.jar
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 29 -> /sys/kernel/debug/tracing/trace_marker
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 3 -> /dev/log/main
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 30 -> /system/framework/framework-res.apk
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 31 -> /system/framework/core.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 32 -> socket:[9549]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 33 -> socket:[225213]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 34 -> /dev/cpuctl/apps/tasks
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 35 -> /dev/cpuctl/apps/bg_non_interactive/tasks
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 36 -> pipe:[225214]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 37 -> pipe:[225214]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 38 -> /dev/binder
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 39 -> pipe:[225217]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 4 -> /dev/log/radio
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 40 -> pipe:[225217]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 41 -> anon_inode:[eventpoll]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 42 -> /data/app/com.mobinet.mobinetbootapp-2.apk
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 43 -> /data/app/com.mobinet.mobinetbootapp-2.apk
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 44 -> socket:[225228]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 45 -> socket:[226446]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 46 -> socket:[226447]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 47 -> socket:[226448]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 48 -> /dev/kgsl-3d0
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 49 -> socket:[225556]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 5 -> /dev/log/events
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 50 -> socket:[225559]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 51 -> /dev/ion
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 52 -> /dev/video3 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 53 -> socket:[225229]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 54 -> anon_inodemabuf
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 55 -> anon_inodemabuf
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 56 -> /dev/ion
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 57 -> socket:[225235]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 58 -> anon_inodemabuf
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 59 -> anon_inodemabuf
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 6 -> /dev/log/system
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 60 -> socket:[226501]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 61 -> socket:[226502]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 62 -> socket:[225236]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 63 -> anon_inode:[eventfd]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 64 -> /dev/video4 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 65 -> /dev/video5
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 66 -> socket:[227519]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 67 -> socket:[227520]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 68 -> anon_inode:[eventfd]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 69 -> socket:[225243]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 7 -> /system/framework/core.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 70 -> socket:[225244]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 71 -> socket:[225245]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 72 -> socket:[225246]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 73 -> /dev/video3 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 74 -> socket:[225249]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 75 -> socket:[225250]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 76 -> socket:[225251]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 77 -> socket:[225252]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 78 -> /dev/video3 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 79 -> socket:[227670]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 8 -> /system/framework/conscrypt.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 80 -> /dev/video4 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 81 -> socket:[227671]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 82 -> /dev/video5
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 83 -> socket:[227527]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 84 -> socket:[227528]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 85 -> socket:[227529]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 86 -> socket:[227530]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 87 -> socket:[227532]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 88 -> socket:[227533]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 89 -> socket:[227534]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 9 -> /dev/__properties__
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 90 -> socket:[227535]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 91 -> /dev/video4 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 92 -> /dev/video5
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 93 -> socket:[227674]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 94 -> socket:[227675]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 95 -> socket:[227676]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 96 -> socket:[227677]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 97 -> /dev/video5
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 98 -> socket:[227686]
root@hammerhead:/ #
root@hammerhead:/ #
root@hammerhead:/ #
root@hammerhead:/ #
root@hammerhead:/ # ls -la /proc/4487/fd                                      
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 0 -> /dev/null
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 1 -> /dev/null
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 10 -> socket:[9230]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 100 -> /dev/video6
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 101 -> socket:[227827]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 102 -> socket:[227682]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 103 -> socket:[227683]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 104 -> socket:[227684]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 105 -> socket:[227685]
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 106 -> /dev/video6
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 107 -> socket:[227821]
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 108 -> socket:[227822]
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 109 -> socket:[227823]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 11 -> /system/framework/okhttp.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 110 -> socket:[227824]
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 111 -> socket:[227825]
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 112 -> socket:[227826]
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 113 -> socket:[227828]
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 114 -> socket:[227829]
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 115 -> socket:[227830]
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 116 -> socket:[227831]
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 117 -> /dev/video6
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 12 -> /system/framework/core-junit.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 13 -> /system/framework/bouncycastle.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 14 -> /system/framework/ext.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 15 -> /system/framework/framework.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 16 -> /system/framework/framework2.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 17 -> /system/framework/telephony-common.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 18 -> /system/framework/voip-common.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 19 -> /system/framework/mms-common.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 2 -> /dev/null
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 20 -> /system/framework/android.policy.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 21 -> /system/framework/services.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 22 -> /system/framework/apache-xml.jar
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 23 -> /system/framework/webviewchromium.jar
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 24 -> /dev/log/main
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 25 -> /dev/log/radio
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 26 -> /dev/log/events
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 27 -> /dev/log/system
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 28 -> /system/framework/framework.jar
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 29 -> /sys/kernel/debug/tracing/trace_marker
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 3 -> /dev/log/main
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 30 -> /system/framework/framework-res.apk
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 31 -> /system/framework/core.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 32 -> socket:[9549]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 33 -> socket:[225213]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 34 -> /dev/cpuctl/apps/tasks
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 35 -> /dev/cpuctl/apps/bg_non_interactive/tasks
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 36 -> pipe:[225214]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 37 -> pipe:[225214]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 38 -> /dev/binder
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 39 -> pipe:[225217]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 4 -> /dev/log/radio
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 40 -> pipe:[225217]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 41 -> anon_inode:[eventpoll]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 42 -> /data/app/com.mobinet.mobinetbootapp-2.apk
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 43 -> /data/app/com.mobinet.mobinetbootapp-2.apk
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 44 -> socket:[225228]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 45 -> socket:[226446]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 46 -> socket:[226447]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 47 -> socket:[226448]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 48 -> /dev/kgsl-3d0
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 49 -> socket:[225556]
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 5 -> /dev/log/events
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 50 -> socket:[225559]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 51 -> /dev/ion
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 52 -> /dev/video3 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 53 -> socket:[225229]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 54 -> anon_inodemabuf
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 55 -> anon_inodemabuf
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 56 -> /dev/ion
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 57 -> socket:[225235]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 58 -> anon_inodemabuf
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 59 -> anon_inodemabuf
l-wx------ u0_a86   u0_a86            2014-06-24 18:42 6 -> /dev/log/system
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 60 -> socket:[226501]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 61 -> socket:[226502]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 62 -> socket:[225236]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 63 -> anon_inode:[eventfd]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 64 -> /dev/video4 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 65 -> /dev/video5 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 66 -> socket:[227519]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 67 -> socket:[227520]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 68 -> /dev/video6
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 69 -> socket:[225243]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 7 -> /system/framework/core.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 70 -> socket:[225244]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 71 -> socket:[225245]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 72 -> socket:[225246]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 73 -> /dev/video3 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 74 -> socket:[225249]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 75 -> socket:[225250]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 76 -> socket:[225251]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 77 -> socket:[225252]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 78 -> /dev/video3 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 79 -> socket:[227670]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 8 -> /system/framework/conscrypt.jar
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 80 -> /dev/video4 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 81 -> socket:[227671]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 82 -> anon_inode:[eventfd]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 83 -> socket:[227527]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 84 -> socket:[227528]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 85 -> socket:[227529]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 86 -> socket:[227530]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 87 -> socket:[227532]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 88 -> socket:[227533]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 89 -> socket:[227534]
lr-x------ u0_a86   u0_a86            2014-06-24 18:42 9 -> /dev/__properties__
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 90 -> socket:[227535]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 91 -> /dev/video4 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 92 -> /dev/video5 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 93 -> socket:[227674]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 94 -> socket:[227675]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 95 -> socket:[227676]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 96 -> socket:[227677]
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 97 -> /dev/video5 (deleted)
lrwx------ u0_a86   u0_a86            2014-06-24 18:42 98 -> socket:[227815]
lrwx------ u0_a86   u0_a86            2014-06-24 18:43 99 -> socket:[227816]
root@hammerhead:/ #
Comment 1 Nicolas Dufresne (ndufresne) 2014-07-04 12:56:09 UTC
For next time, you should attach the logs, it keeps the thread easier to read. Thanks for the bug report, we will have a look shortly. If you could provide some C code to reproduce it would save us a bit of time.
Comment 2 Lee Matthews 2014-07-08 12:04:19 UTC
Created attachment 280139 [details]
Some Android native C code that reproduces the potential bug
Comment 3 Lee Matthews 2014-07-08 12:12:09 UTC
Created attachment 280140 [details]
A text dump of 'ls -la /proc/PID/fd' after the code has finished executing
Comment 4 Lee Matthews 2014-07-08 12:14:41 UTC
I've created some code to reproduce the issue. It basically cycles through device node video3 to video8 trying to create a pipeline (v4l2src to fakesink). 

Initially (if the webcam is plugged in) the code uses video3. On un-plugging the camera the code tries to open a pipeline on device /dev/video3, if it fails it moves to /dev/video4 and so on. 

As one unplugs/replugs the camera, the device node number goes up and up, only ever returning to video3 once the application is closed and the the camera is unplugged/plugged-in one last time.

I've also attached a dump of /proc/$PID/fs on my Android phone.

I hope this helps.

Lee
Comment 5 Charles 2014-08-21 15:05:46 UTC
I'm seeing the same issue on Linux / x86.  Happens with both 0.10.36, and 1.2.4.  Device number goes up and up, until I close my application.
Comment 6 Charles 2014-08-21 20:13:25 UTC
Created attachment 284141 [details]
lsof output

lsof output attached.

When I yank the cable, most of the entries for /dev/video1 disappear.  Three remain, with a an FD/TYPE of DEL/REG.  These entries remain until I close the application.
Comment 7 Charles 2014-08-21 20:23:46 UTC
Created attachment 284143 [details]
GST_DEBUG output

GST_DEBUG output attached.  Starts approximately when the device was unplugged.

The last thing reported by v4l2 seems to be "Trying to close /dev/video1".
Comment 8 Nicolas Dufresne (ndufresne) 2014-09-09 23:01:09 UTC
Ok, I can confirm this using Cheese, looks like an FD leak indeed.
Comment 9 Nicolas Dufresne (ndufresne) 2015-01-08 16:23:18 UTC
Ok, a simple way to produce:

1. Plug the camera
2. Run:
GST_DEBUG=v4l2allocator:7 gst-launch-1.0  v4l2src device=/dev/video2 ! videoconvert ! xvimagesink
3. Unplug the camera

Notice that the Allocator is never finalized. The allocator has a reference on the device FD.

What seems to happens, is that when trying to pull down the device, STREAMOFF failed (error 19) and we assumed that pulling it down failed. Solution will be to either ignore streamoff error or handle errno 19.
Comment 10 Nicolas Dufresne (ndufresne) 2015-01-08 16:31:35 UTC
Btw, 19 is ENODEV, in V4L2 context it's very clear:

"Device not found or was removed."

I don't see any error reported by STREAMOFF for which we would still be streaming. There is only EBUSY, but it make no sense, this is what other ioctl may return if STREAMOFF need to be called first. This would be a deadend.

So the change I would do is to warn on error, but still assume we are no longer streaming. This way, at worst other call will fail later and device will be closed properly (the only solution when the device is not responding).
Comment 11 Nicolas Dufresne (ndufresne) 2015-01-08 16:43:44 UTC
Created attachment 294105 [details] [review]
v4l2bufferpool: Never fail on streamoff

This patches fixes it for me, I'll do more tests and merge.
Comment 12 Nicolas Dufresne (ndufresne) 2015-01-09 04:57:21 UTC
Comment on attachment 294105 [details] [review]
v4l2bufferpool: Never fail on streamoff

commit a4b961e27503a257c49ba6d059cc70ce8e691bd6
Author: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk>
Date:   Thu Jan 8 11:37:23 2015 -0500

    v4l2bufferpool: Never fail on streamoff
    
    Failing streamoff prevents allocator from being disposed hence
    lead to device FD leak. There is no known cases where streamoff
    may fails for which we'd still be streaming. streamoff is known
    to fail when a device is being unplugged (in which case errno
    19/ENODEV is set).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=732734
Comment 13 Nicolas Dufresne (ndufresne) 2015-01-09 05:02:20 UTC
Also in 1.4
efc5332 v4l2bufferpool: Never fail on streamoff