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

Unsafe usage of pointers #8

Open
mgw93 opened this issue Nov 5, 2022 · 2 comments
Open

Unsafe usage of pointers #8

mgw93 opened this issue Nov 5, 2022 · 2 comments

Comments

@mgw93
Copy link

mgw93 commented Nov 5, 2022

I noticed that there are several instances where pointers obtained from unsafe_convert are used without preserving the underlying object from garbage collection.

E.g. in the uhd_usrp_create_stream function.

I’m pretty new to Julia myself, but my understanding is that this can lead to bugs when the garbage collector removes an object before the pointer is used.

@RGerzaguet
Copy link
Member

Thanks for the feedback,
This is true than unsafe_load can lead to un-protected memory but AFAIK it is prevented by the use of the Ref{} in the structure as it stores the result of the unsafe_load. So It should not lead to seg fault that way (even the approach here is unsafe :)).
Did you encounter any problem of GC-ed variables with UHDBindings ?

@mgw93
Copy link
Author

mgw93 commented Nov 7, 2022

I have not experienced any actual issues.
However, the nature of memory safety issues is that they often only manifest themselves in rare circumstances.
Most of the time (or possibly always until someone changes the implementation) the garbage collector does not get in the way.
But unless it’s guaranteed that it won’t happen, it’s still an issue.

I’m still new to Julia and may therefore be misunderstanding the guarantees that are provided by the language,
but the way I see it, if the garbage collector was triggered on line 126 of Rx.jl, it would be allowed to collect cpu_format, otw_format, args, and channels, all of which need to still be alive for the call to uhd_usrp_get_rx_stream on line 130.
The fact that the variables are still in scope does not help, as the compiler can determine that they are not used (directly) anymore.

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

2 participants