diff --- vm/vmcore/src/init/properties.cpp | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/vm/vmcore/src/init/properties.cpp b/vm/vmcore/src/init/properties.cpp index 7e0aac3..4fd79e2 100644 --- a/vm/vmcore/src/init/properties.cpp +++ b/vm/vmcore/src/init/properties.cpp @@ -15,6 +15,8 @@ * limitations under the License. */ +#include + #define LOG_DOMAIN "init.properties" #include "cxxlog.h" #include "properties.h" @@ -46,14 +48,24 @@ Properties::Properties() void Properties::set(const char * key, const char * value) { + char* key_dup; TRACE("set property " << key << " = " << value); if (APR_SUCCESS != apr_thread_rwlock_wrlock(rwlock_array)) { LDIE(11, "Cannot lock properties table"); } + // If the key is not in the hash we should allocate it on local_ht_pool, + // otherwise we do not want to put the key duplicate into the pool as a + // garbage. PropValue* val = (PropValue*) apr_hash_get(hashtables_array, (const void*) key, APR_HASH_KEY_STRING); - apr_hash_set(hashtables_array, (const void*) strdup(key), APR_HASH_KEY_STRING, (const void*) new PropValue(value)); if (val != NULL) { + key_dup = strdup(key); + }else{ + key_dup = apr_pstrdup(local_ht_pool, key); + } + apr_hash_set(hashtables_array, key_dup, APR_HASH_KEY_STRING, (const void*) new PropValue(value)); + if (val != NULL) { + delete(key_dup); delete(val); } if (APR_SUCCESS != apr_thread_rwlock_unlock(rwlock_array)) {