The get_os_release C function allocates the buffer on the heap and returns it, but on the rust side it doesn't take ownership of the memory:
buf = malloc(LEN);
let typ = ffi::CStr::from_ptr(rp).to_bytes();
Also, if an error occurs on the C side it uses strncpy to set it to "Unknown", but on rust's side it expects a NULL pointer to be returned in case of error:
// At this point `len` is _most likely_ set to `0` (e.g. in case of ENOMEM).
// We copy our string and reset the length.
strncpy(buf, "Unknown", LEN);
if rp == std::ptr::null() {
Err(Error::Unknown)
}
There are other heap allocations on the C side I haven't verified are handled correctly on rust's side.
The
get_os_release
C function allocates the buffer on the heap and returns it, but on the rust side it doesn't take ownership of the memory:Also, if an error occurs on the C side it uses strncpy to set it to "Unknown", but on rust's side it expects a NULL pointer to be returned in case of error:
There are other heap allocations on the C side I haven't verified are handled correctly on rust's side.