settings: Add destructor that wipes contents

This commit is contained in:
Tobias Brunner
2021-10-04 11:30:03 +02:00
parent 57faf886db
commit f3a5b54ab3
3 changed files with 46 additions and 5 deletions
+29 -4
View File
@@ -1071,13 +1071,37 @@ METHOD(settings_t, load_string_section, bool,
return extend_section(this, parent, section, merge);
}
CALLBACK(clear_content, void,
char *str, int idx, void *clear)
{
if (*(bool*)clear)
{
memwipe(str, strlen(str));
}
free(str);
}
/**
* Destroy the settings object and optionally clear content memory
*/
static void destroy_settings(private_settings_t *this, bool clear)
{
settings_section_destroy(this->top, clear ? this->contents : NULL);
array_destroy_function(this->contents, clear_content, &clear);
this->lock->destroy(this->lock);
free(this);
}
METHOD(settings_t, destroy, void,
private_settings_t *this)
{
settings_section_destroy(this->top, NULL);
array_destroy_function(this->contents, (void*)free, NULL);
this->lock->destroy(this->lock);
free(this);
destroy_settings(this, FALSE);
}
METHOD(settings_t, destroy_clear, void,
private_settings_t *this)
{
destroy_settings(this, TRUE);
}
static private_settings_t *settings_create_base()
@@ -1105,6 +1129,7 @@ static private_settings_t *settings_create_base()
.load_string = _load_string,
.load_string_section = _load_string_section,
.destroy = _destroy,
.destroy_clear = _destroy_clear,
},
.top = settings_section_create(NULL),
.contents = array_create(0, 0),