Zero on Free

Users also have the option of zeroing memory whenever it is freed or reset using the memory heap functions. In sensitive applications, this can prevent exploits that depend on reading data from memory after it is freed by the calling application.

In order to activate zero on free, users will need to set a flag in the runtime context heap:

   OSCTXT ctxt;
   int heap_flag = RT_MH_ZEROONFREE, stat = 0;

   stat = rtInitContext (&ctxt);
   if (stat != 0) {
      rtxErrPrint (&ctxt);
      return stat;
   }

   rtxMemHeapSetProperty (&ctxt.pMemHeap, OSRTMH_PROPID_SETFLAGS,
      (void *) &heap_flag);
            

There are two caveats to zeroing memory on free. First, it is a slow operation and will noticeably degrade performance in most cases. Second, it will leave some metadata behind. The data describe the size of the allocated blocks, but not the content. Internally these data are used to navigate through the memory heap, and they must be retained until the blocks are resized (e.g., by a user call to rtxMemFree or by a request that causes an available block to be joined to another).