Function libyml::memory::yaml_free

source ·
pub unsafe fn yaml_free(ptr: *mut c_void)
Expand description

Free memory allocated by yaml_malloc or yaml_realloc.

This function deallocates the memory previously allocated by yaml_malloc or yaml_realloc.

§Arguments

  • ptr - A pointer to the memory block to free. If null, no operation is performed.

§Safety

This function is unsafe because:

  • It directly calls the system’s free function, which is not memory-safe.
  • The caller must ensure that ptr was allocated by yaml_malloc or yaml_realloc.
  • After calling this function, ptr becomes invalid and must not be used.

§Examples

use libyml::memory::{yaml_malloc, yaml_free};
use libyml::yaml::size_t;

unsafe {
    let size: size_t = 1024;
    let ptr = yaml_malloc(size);
    if !ptr.is_null() {
        // Use the allocated memory
        // ...
        yaml_free(ptr);
        // ptr is now invalid and must not be used
    }
}