• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Unexpected segfault when working with raw pointers

Resolved: Unexpected segfault when working with raw pointers

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Initially I wrote a Heap implementation in Rust, but I was getting strange segfaults, so I narrowed down the code to this example, which reproduces the behavior.
Playground.
The result I get from this is:
The interesting thing (to me) is that if I remove the print of c, there is no segfault and the correct value is printed for the heap root.
I expect that anything happening with c can’t affect heap, but it does. What am I missing?

Answer:

You’ve got a use-after-free. In push(), you assign a temporary to self.root. The temporary’s lifetime is finished of the statement and you’re pointing to freed memory. Any further use will cause undefined behavior.
Miri reports it (Tools->Miri in the playground):
Since you’ve got UB, the program can do anything, and any change may affect what it does, even if it seems unrelated.

If you have better answer, please add a comment about this, thank you!

raw-pointer rust segmentation-fault
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How can I modify formData before sending it?

01/04/2023

Resolved: How to efficient create SimpleITK image?

01/04/2023

Resolved: How can I write CSS selector(s) that apply to table rows for all td elements on that row after a td with a certain class?

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.