Skip to content

Add GC.@preserve where pointer() is used#72

Merged
fhs merged 1 commit intofhs:masterfrom
c42f:cjf/gc-preserve
Sep 3, 2020
Merged

Add GC.@preserve where pointer() is used#72
fhs merged 1 commit intofhs:masterfrom
c42f:cjf/gc-preserve

Conversation

@c42f
Copy link
Contributor

@c42f c42f commented Sep 3, 2020

This should fix #71

Using the value returned by pointer() is unsafe unless Julia is told
to preserve the owner of that memory. GC.@preserve is the right way to
do this. In some cases the GC.@preserve used here may cover a
slightly larger scope than may be strictly necessary. But this should be ok,
as it's essentially free.

Also set the pointer fields next_in and next_out to C_NULL
whenever we're finished with them to prevent use-after-free surprises.
While not exactly necessary in an ideal bug-free world, this should help
with robustness by detecting any accidental reuse of stale buffers.

Using the value returned by `pointer()` is unsafe unless Julia is told
to preserve the owner of that memory. GC.@ preserve is the right way to
do this.

Also set the pointer fields `next_in` and `next_out` to `C_NULL`
whenever we're finished with them to prevent use-after-free surprises.
While not exactly necessary in an ideal bug-free world, this should help
with robustness by detecting any accidental reuse of stale buffers.
@c42f
Copy link
Contributor Author

c42f commented Sep 3, 2020

Hmm. The FreeBSD CI failures seem like a CI config problem.

Copy link
Owner

@fhs fhs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

I think I've fixed the FreeBSD CI issue (at least for Julia 1.3).

@fhs fhs merged commit e916fd9 into fhs:master Sep 3, 2020
@c42f c42f deleted the cjf/gc-preserve branch September 4, 2020 05:50
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.

Missing GC.@preserve

2 participants