Commit 2fef98a5 authored by topjohnwu's avatar topjohnwu

Wipe out prop_info data after delete

parent 36765cae
...@@ -276,11 +276,11 @@ prop_bt* prop_area::find_prop_bt(prop_bt* const bt, const char* name, uint32_t n ...@@ -276,11 +276,11 @@ prop_bt* prop_area::find_prop_bt(prop_bt* const bt, const char* name, uint32_t n
/* resetprop new: traverse through the trie and find the node. /* resetprop new: traverse through the trie and find the node.
* This was originally part of prop_area::find_property. */ * This was originally part of prop_area::find_property. */
prop_bt *prop_area::find_prop_bt(prop_bt *const trie, const char *name, bool alloc_if_needed) { prop_bt *prop_area::find_prop_bt(prop_bt *const bt, const char *name, bool alloc_if_needed) {
if (!trie) return nullptr; if (!bt) return nullptr;
const char* remaining_name = name; const char* remaining_name = name;
prop_bt* current = trie; prop_bt* current = bt;
while (true) { while (true) {
const char* sep = strchr(remaining_name, '.'); const char* sep = strchr(remaining_name, '.');
const bool want_subtree = (sep != nullptr); const bool want_subtree = (sep != nullptr);
...@@ -381,11 +381,30 @@ bool prop_area::add(const char* name, unsigned int namelen, const char* value, ...@@ -381,11 +381,30 @@ bool prop_area::add(const char* name, unsigned int namelen, const char* value,
} }
bool prop_area::rm(const char *name) { bool prop_area::rm(const char *name) {
prop_bt* node = find_prop_bt(root_node(), name, false); prop_bt *node = find_prop_bt(root_node(), name, false);
if (!node) if (!node)
return false; return false;
prop_info *info = nullptr;
uint_least32_t prop_offset = atomic_load_explicit(&node->prop, memory_order_relaxed);
if (prop_offset != 0) {
info = to_prop_info(&node->prop);
}
// De-reference the existing property ASAP
uint_least32_t new_offset = 0; uint_least32_t new_offset = 0;
atomic_store_explicit(&node->prop, new_offset, memory_order_release); atomic_store_explicit(&node->prop, new_offset, memory_order_release);
if (info) {
// Directly wipe out the old info
if (info->is_long()) {
char *value = const_cast<char*>(info->long_value());
auto len = strlen(value);
memset(value, 0, len);
}
memset(info, 0, sizeof(*info));
}
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment