42
6
Fork
You've already forked steve
1

Fix memory leak of pollhandle in steve_poll() #2

Manually merged
mgorny merged 1 commit from flow/steve:fix-memleak into main 2026年05月23日 08:25:20 +02:00
Member
Copy link

The steve_poll() function would leak memory in form of the pollhandle
in case a token is immediately available. Because then the pollhandle
is not placed in the waiters queue, where it is eventually deallocated
via the ~steve_waiter destructor.

Fix this my explicitly destroying the pollhandle if we do not put it
in the waiters queue.

Signed-off-by: Florian Schmaus flow@gentoo.org

The steve_poll() function would leak memory in form of the pollhandle in case a token is immediately available. Because then the pollhandle is not placed in the waiters queue, where it is eventually deallocated via the ~steve_waiter destructor. Fix this my explicitly destroying the pollhandle if we do not put it in the waiters queue. Signed-off-by: Florian Schmaus <flow@gentoo.org>
src/steve.cxx Outdated
@ -791,2 +791,3 @@
events &= ~POLLIN;
}
} else if (ph)
fuse_pollhandle_destroy(ph);
Owner
Copy link

Is it really safe to destroy it prior to replying? I would feel safer if you moved this to the bottom.

Is it really safe to destroy it prior to replying? I would feel safer if you moved this to the bottom.
Author
Member
Copy link

I think it is. I've been running with this for a a while without issues. Furthermore, this variant keeps the life cycle management of the poll handle relatively local, and hence reduces the LoC requires, so it's what I would prefer.

However, if you feel like it's necessary, then I can move it to the bottom. Let me know what you think.

I think it is. I've been running with this for a a while without issues. Furthermore, this variant keeps the life cycle management of the poll handle relatively local, and hence reduces the LoC requires, so it's what I would prefer. However, if you feel like it's necessary, then I can move it to the bottom. Let me know what you think.
Owner
Copy link

Please move it. Let's not risk, especially with CUSE documentation barely existing, and the guarantees there possibly changing in the future.

Please move it. Let's not risk, especially with CUSE documentation barely existing, and the guarantees there possibly changing in the future.
Author
Member
Copy link

Done

Done
@ -791,2 +792,3 @@
events &= ~POLLIN;
}
} else
destroy_ph = (ph != nullptr);
Owner
Copy link

Is there a case when it's nullptr?

Is there a case when it's `nullptr`?
Author
Member
Copy link

See #5 and github.com/libfuse/libfuse@d999bd63af/lib/fuse_lowlevel.c (L2418) and github.com/libfuse/libfuse@d999bd63af/include/fuse_lowlevel.h (L1093) which hints towards the possiblity of ph being null (but fuse documentation is not that good, as you already noticed).

It comes down to the kernel not setting FUSE_POLL_SCHEDULE_NOTIFY for non blocking polls in https://elixir.bootlin.com/linux/v7.0.9/source/fs/fuse/file.c#L2748-L2751

See https://codeberg.org/gentoo/steve/pulls/5 and https://github.com/libfuse/libfuse/blob/d999bd63afee30949443dc237e3a1f210d0c43e0/lib/fuse_lowlevel.c#L2418 and https://github.com/libfuse/libfuse/blob/d999bd63afee30949443dc237e3a1f210d0c43e0/include/fuse_lowlevel.h#L1093 which hints towards the possiblity of `ph` being `null` (but fuse documentation is not that good, as you already noticed). It comes down to the kernel not setting `FUSE_POLL_SCHEDULE_NOTIFY` for non blocking polls in https://elixir.bootlin.com/linux/v7.0.9/source/fs/fuse/file.c#L2748-L2751
mgorny manually merged commit 7320b971e3 into main 2026年05月23日 08:25:20 +02:00
Sign in to join this conversation.
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
gentoo/steve!2
Reference in a new issue
gentoo/steve
No description provided.
Delete branch "flow/steve:fix-memleak"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?