The function mtrace installs handlers for malloc, realloc and free; the function muntrace disables these handlers.
The handlers log all memory allocations and frees to a file defined by the environment variable MALLOC_TRACE (if the variable is unset, describes an invalid filename, or describes a filename the user does not have permissions to, the handlers are not installed).