Skip to content
Permalink
Browse files
Fix memory leaks
  • Loading branch information
bblough committed Aug 21, 2018
1 parent 2cdf772 commit 7349424f4528abf29ddf66e04ac166b4407b006f
Showing 2 changed files with 41 additions and 9 deletions.
@@ -374,17 +374,22 @@ axis2_conf_free(
if(conf->name_to_version_map)
{
axutil_hash_index_t *hi = NULL;
void *key = NULL;
void *val = NULL;
for(hi = axutil_hash_first(conf->name_to_version_map, env); hi; hi = axutil_hash_next(env,
hi))
{
axis2_char_t *module_ver = NULL;
axutil_hash_this(hi, NULL, NULL, &val);
axutil_hash_this(hi, &key, NULL, &val);
module_ver = (axis2_char_t *)val;
if(module_ver)
{
AXIS2_FREE(env->allocator, module_ver);
}
if(key)
{
AXIS2_FREE(env->allocator, key);
}
}
axutil_hash_free(conf->name_to_version_map, env);
}
@@ -1713,7 +1718,14 @@ axis2_conf_add_default_module_version(
{
return AXIS2_FAILURE;
}
axutil_hash_set(name_to_ver_map, module_name, AXIS2_HASH_KEY_STRING, new_entry);
axis2_char_t *new_name = axutil_strdup(env, module_name);
if(!new_entry)
{
AXIS2_FREE(env->allocator, new_entry);
return AXIS2_FAILURE;
}

axutil_hash_set(name_to_ver_map, new_name, AXIS2_HASH_KEY_STRING, new_entry);
return AXIS2_SUCCESS;
}
return AXIS2_FAILURE;
@@ -352,30 +352,44 @@ axis2_core_utils_calculate_default_module_version(
if(module_ver_str && AXIS2_TRUE == axis2_core_utils_is_latest_mod_ver(env,
module_ver_str, current_def_ver))
{
axis2_char_t *old_ver = NULL;
old_ver = axutil_hash_get(default_modules,
module_name_str,
AXIS2_HASH_KEY_STRING);
if (old_ver) {
AXIS2_FREE(env->allocator, old_ver);
old_ver = NULL;
}
axutil_hash_set(default_modules, module_name_str,
AXIS2_HASH_KEY_STRING, module_ver_str);
AXIS2_FREE(env->allocator, module_name_str);
module_name_str = NULL;
}
else
{
if(module_name_str)
{
AXIS2_FREE(env->allocator, module_name_str);
module_name_str = NULL;
}
if(module_ver_str)
{
AXIS2_FREE(env->allocator, module_ver_str);
module_ver_str = NULL;
}
}
}
else
{
axutil_hash_set(default_modules, module_name_str, AXIS2_HASH_KEY_STRING,
module_ver_str);
}

if(module_name_str)
{
AXIS2_FREE(env->allocator, module_name_str);
if (module_ver_str)
{
axutil_hash_set(default_modules, module_name_str, AXIS2_HASH_KEY_STRING,
module_ver_str);
}
else
{
AXIS2_FREE(env->allocator, module_name_str);
}
}
}
}
@@ -395,6 +409,12 @@ axis2_core_utils_calculate_default_module_version(
(axis2_char_t *)val);
AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Added default module"
" version : %s for module : %s", (axis2_char_t *)val, (axis2_char_t *)key_string);
AXIS2_FREE(env->allocator, val);
/* the key stored in the hash is the dynamically allocated module_name,
* so to avoid a memleak we have to free it before freeing the hash.
* TODO: find a better way to deal with this
*/
AXIS2_FREE(env->allocator, key_string);
}
}

0 comments on commit 7349424

Please sign in to comment.