Skip to content

(master) wcmConfig: fix fd_refs double-increment in wcmDevOpen() - #18

Open
metux wants to merge 1 commit into
masterfrom
pr/master-wcmconfig-fix-fd-refs-double-increment-in-wcmdevopen-_2026-07-07_13-34-41
Open

(master) wcmConfig: fix fd_refs double-increment in wcmDevOpen()#18
metux wants to merge 1 commit into
masterfrom
pr/master-wcmconfig-fix-fd-refs-double-increment-in-wcmdevopen-_2026-07-07_13-34-41

Conversation

@metux

@metux metux commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

For the device that performs the actual open (common->fd_refs == 0),
wcmDevOpen() opened the physical fd and set common->fd_refs = 1, but
never gave that same priv its own fd via wcmSetFd(). The following
'grab the common descriptor if available' block then saw
wcmGetFd(priv) still < 0 for that same priv and ran anyway, calling
wcmSetFd() again and incrementing common->fd_refs a second time for
what is really only one logical reference.

wcmDevClose() decrements fd_refs exactly once per priv whose own fd is

= 0, so the extra increment meant fd_refs never returned to 0 on
close, leaking the underlying fd on every plug/unplug cycle.

Fix by setting the just-opened priv's own fd right where the open
happens, so the fallback block's wcmGetFd(priv) < 0 check correctly
sees it as already satisfied and skips the redundant increment.

Signed-off-by: Enrico Weigelt, metux IT consult info@metux.net

For the device that performs the actual open (common->fd_refs == 0),
wcmDevOpen() opened the physical fd and set common->fd_refs = 1, but
never gave that same priv its own fd via wcmSetFd(). The following
'grab the common descriptor if available' block then saw
wcmGetFd(priv) still < 0 for that same priv and ran anyway, calling
wcmSetFd() again and incrementing common->fd_refs a second time for
what is really only one logical reference.

wcmDevClose() decrements fd_refs exactly once per priv whose own fd is
>= 0, so the extra increment meant fd_refs never returned to 0 on
close, leaking the underlying fd on every plug/unplug cycle.

Fix by setting the just-opened priv's own fd right where the open
happens, so the fallback block's wcmGetFd(priv) < 0 check correctly
sees it as already satisfied and skips the redundant increment.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant