plugins/default: visit_rc() leaks file descriptor
Thomas Betker <[email protected]> Sun, 4 Sep 2022 15:54:54 +0200
| Newsgroups | gmane.comp.hardware.lirc |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --------------C4E4m0wykI3n0099vk8w7qZx Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Dear LIRC maintainers, visit_rc() opens /sys/class/rc/rc1/protocols O_RDONLY, but never closes it, so the file stays open forever. [fd is overwritten by another O_WRONLY open a few lines later; that one is closed correctly, though.] In my case (lirc-0.10.1 on openSUSE Leap 15.4, 'irw' running, 'lircd' failing to open /dev/lirc1 due to permission issues), this means that 'lircd' creates a new /sys/class/rc/rc1/protocols file descriptor every second, sometimes resulting in hundreds of /proc/$PID/fd/ entries. Apparently, this was introduced by commit 06bd6d "plugins/default: Just check lirc protocol if read-only access (#133)." on 17-Sep-2015. I would suggest closing fd right after reading it; please see my attached patch (not tested). Best regards, Thomas Betker --------------C4E4m0wykI3n0099vk8w7qZx Content-Type: text/plain; charset=UTF-8; name="fix-fd-leak.patch" Content-Disposition: attachment; filename="fix-fd-leak.patch" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3BsdWdpbnMvZGVmYXVsdC5jIGIvcGx1Z2lucy9kZWZhdWx0LmMKaW5k ZXggZjRkMDM1OTguLmIyNDEwOWQ0IDEwMDY0NAotLS0gYS9wbHVnaW5zL2RlZmF1bHQuYwor KysgYi9wbHVnaW5zL2RlZmF1bHQuYwpAQCAtMTUxLDYgKzE1MSw3IEBAIHN0YXRpYyBpbnQg dmlzaXRfcmMoY29uc3QgY2hhciogcmNfZGlyLCBjb25zdCBjaGFyKiBkZXZpY2UpCiAJCXJl dHVybiAtMTsKIAl9CiAJciA9IHJlYWQoZmQsIGJ1ZmYsIHNpemVvZihidWZmKSk7CisJY2xv c2UoZmQpOwogCWlmIChyIDwgMCkgewogCQlsb2dfZGVidWcoIkNhbm5vdCByZWFkIGZyb20g JXMiLCBwYXRoKTsKIAkJcmV0dXJuIC0xOwo= --------------C4E4m0wykI3n0099vk8w7qZx Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --------------C4E4m0wykI3n0099vk8w7qZx--