Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Letting users hold on to a Buffer object is unsafe. #15

Closed
poljar opened this issue Nov 10, 2019 · 1 comment
Closed

Letting users hold on to a Buffer object is unsafe. #15

poljar opened this issue Nov 10, 2019 · 1 comment

Comments

@poljar
Copy link
Owner

poljar commented Nov 10, 2019

A Weechat buffer can be either created or searched for using the Weechat object e.g.:

 let buffer: Buffer = weechat.buffer_new(None, Some(input_cb)...);

At the time of creation/search this buffer object will almost always be valid, and we can use it without any fear of it disappearing. Once we give control back to Weechat an user could close the buffer rendering our object invalid.

One way to solve this is to only give users access to a reference of the Weechat object and bind the lifetime of the Buffer to the Weechat object with a PhantomData field.

This should certainly be done for the buffers that are returned with the weechat.buffer_search() method since there is no way of knowing when the buffer gets destroyed.

For Buffers that are created by our own plugin the buffer_close callback will get called before the object will become invalid. We could let users keep the Buffer object but have them unlock it which checks if the buffer was destroyed.

@poljar
Copy link
Owner Author

poljar commented Mar 6, 2020

This has been fixed by 5df6c35 and a couple of commits after this one.

@poljar poljar closed this as completed Mar 6, 2020
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

No branches or pull requests

1 participant