title: Security of the Libsodium function sodium_malloc() and sodium_free()
body: <p>I am realizing a small program to encrypt messages.
  To do this I use Libsodium.</p>
  <p>I need to dynamically allocate sensitive data, to do this I use <a href="https://libsodium.gitbook.io/doc/memory_management#guarded-heap-allocations" rel="nofollow noreferrer">Libsodium functions</a>,</p>
  <p>I read the documentation and for some doubts I inquired on intenet but of the answers I found my doubts grew, so:</p>
  <p><code>sodium_malloc()</code> and <code>sodium_free()</code> are functions for dynamic memory allocation and cleaning that also take care of their security?</p>
  <p>By security, I mean that data allocated dynamically in memory cannot be read and/or overwritten by other programs that try to access the area of memory, allocated with <code>sodium_malloc</code>, that is in use by my program; and when I call <code>sodium_free</code> before freeing the memory it is overwritten.</p>