`Strings::as_slice` is either unsound or leaks memory
- Dominant language
- Rust
- Stars
- 528
- Forks
- 58
- PR merge metrics
- No merged PRs in 30d
Description
### Pre-flight checklist
- [x] I have searched existing issues and this is not a duplicate
### Expected behavior
The signature of `Strings::as_slice` is the following:
```rs
pub fn as_slice<'a>(&self) -> &'a [Rstr] {
```
This allows the caller to choose an arbitrary lifetime, e.g. `'static`. This implies one of two things about the implementation:
1. It leaks memory.
2. It is unsound, as the reference is allowed to live longer than the `Strings` itself.
### Current behavior
I haven’t checked what the current behaviour is, but either alternative above is bad. If it leaks memory, there should at least be a warning about this in docs.
### Steps to reproduce
Go to [`Strings::as_slice`](https://docs.rs/extendr-api/latest/extendr_api/wrapper/strings/struct.Strings.html#method.as_slice).
### Possible solution
If the lifetime of `[Rstr]` is tied to the lifetime of the `Strings`, it should return `&[Rstr]` and have no `'a` lifetime.
### Environment
extendr 0.9.0
Contributor guide
Research direction
Start at the linked Strings::as_slice entry point and inspect its implementation and lifetime relationship with Strings. Confirm whether the returned slice can outlive its owner or whether memory is leaked, then make the API lifetime-safe or document the leak and add coverage demonstrating the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100