fix memory leak, remove blanket pointer-by-value impls

This commit is contained in:
Dustin J. Mitchell
2022-02-12 01:15:32 +00:00
parent 76cbc2880b
commit e9cd6adc5b
5 changed files with 81 additions and 92 deletions

View File

@@ -95,12 +95,11 @@ pub unsafe extern "C" fn tc_annotation_free(tcann: *mut TCAnnotation) {
/// When this call returns, the `items` pointer will be NULL, signalling an invalid TCAnnotationList.
#[no_mangle]
pub unsafe extern "C" fn tc_annotation_list_free(tcanns: *mut TCAnnotationList) {
debug_assert!(!tcanns.is_null());
// SAFETY:
// - *tcanns is a valid TCAnnotationList (caller promises to treat it as read-only)
let annotations =
unsafe { TCAnnotationList::take_from_arg(tcanns, TCAnnotationList::null_value()) };
TCAnnotationList::drop_vector(annotations);
// - tcanns is not NULL and points to a valid TCAnnotationList (caller is not allowed to
// modify the list)
// - caller promises not to use the value after return
unsafe { drop_value_array(tcanns) }
}
#[cfg(test)]