Say I have a Rust function meant to be called from C code:
#[unsafe(no_mangle)]
extern "C" fn foo() -> *mut u8 {
unsafe { libc::malloc(42) }
}
Can I free the return value of this function in C code with:
#include <stdlib.h>
int main(void) {
uint8_t* x = foo();
free(x);
return 0;
}
Are there any dangerous assumptions being made here using free to free the return value of foo?