Just for case ensure compiler is not able to optimize
memset() away for resources that are released.
This idea of using memory barrier is taken from openssl.
Other options would be to check for 'explicit_bzero' function.
{
if (string) {
memset(string, 0, strlen(string));
+ asm volatile ("" ::: "memory"); /* Compiler barrier. */
free(string);
}
}
{
if (dmi) {
memset(dmi, 0, dmi->data_size);
+ asm volatile ("" ::: "memory"); /* Compiler barrier. */
free(dmi);
}
}
{
if (string) {
memset(string, 0, strlen(string));
+ asm volatile ("" ::: "memory"); /* Compiler barrier. */
dm_free(string);
}
}
{
if (dmi) {
memset(dmi, 0, dmi->data_size);
+ asm volatile ("" ::: "memory"); /* Compiler barrier. */
dm_free(dmi);
}
}