Skip to content

Commit

Permalink
Decrement refcount before calling free in to_next_sibling
Browse files Browse the repository at this point in the history
Fixes an assertion in debug builds which I accidentally
introduced when attending the review comments for [1]
in [2] - instead of only removing the increment, I also
removed the decrement which was wrong - `std::mem::forget`
only allows us to remove the increment, but the decrement
is still needed before free since we are in a place of
code that is by definition only run when the rc value is set to 1.
See also `can_take_ptr`.

I did not spot this earlier since I ran the integration test
on a release build, where the assertion was disabled. It's sad
that the rowan repo itself doesn't have any big test coverage
in this repo itself, but rather relies on external repos for
testing purposes...

[1]: #171 (comment)
[2]: https://github.com/rust-analyzer/rowan/compare/60a632ad984ab451e32058169193511154c675a9..ab5463e2749330be6846886c21e98c83caca8598

Fixes: #172
  • Loading branch information
milianw committed Oct 31, 2024
1 parent 4bc8ba0 commit 3294973
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ impl SyntaxNode {
Some(SyntaxNode { ptr })
})
.or_else(|| {
data.dec_rc();
unsafe { free(ptr) };
None
})
Expand Down Expand Up @@ -1234,6 +1235,7 @@ impl SyntaxElement {
}
})
.or_else(|| {
data.dec_rc();
unsafe { free(ptr) };
None
})
Expand Down

0 comments on commit 3294973

Please sign in to comment.