summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar damitha2010-06-27 05:45:57 +0000
committerGravatar damitha2010-06-27 05:45:57 +0000
commit3203263e743a2e940a4f8c874b1f3952308d67bc (patch)
treebfc91566df6c9f7ff730faaffdadc85d9e4b210c /src
parent2de825a4caa24239c791b3301acfc6d38a44b44e (diff)
downloadaxis2c-3203263e743a2e940a4f8c874b1f3952308d67bc.tar.gz
axis2c-3203263e743a2e940a4f8c874b1f3952308d67bc.tar.bz2
Fixing memory leak in http cookie session implementation
git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@958325 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/core/transport/http/util/http_transport_utils.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/core/transport/http/util/http_transport_utils.c b/src/core/transport/http/util/http_transport_utils.c
index 0d96180..6173d7c 100644
--- a/src/core/transport/http/util/http_transport_utils.c
+++ b/src/core/transport/http/util/http_transport_utils.c
@@ -3549,6 +3549,10 @@ axis2_http_transport_utils_get_session(
sprintf(session_value, "%s", "");
+ /* Note that in addition to storing the values in the session table into a string, we also
+ * free the session table entries in the following loop, because we are going to store them
+ * into the session database.
+ */
for(hi = axutil_hash_first(ht, env); hi; hi = axutil_hash_next(env, hi))
{
axis2_char_t *name = NULL;
@@ -3580,6 +3584,7 @@ axis2_http_transport_utils_get_session(
AXIS2_FREE(env->allocator, header_value);
return NULL;
}
+ /* Store the session in the session database */
status = AXIS2_HTTP_OUT_TRANSPORT_INFO_SET_SESSION(out_info, env, session_id, session_value);
if(status != AXIS2_SUCCESS)
{
@@ -3590,11 +3595,34 @@ axis2_http_transport_utils_get_session(
}
else
{
+ /* This means session is already created in a previous request.*/
time_str = axutil_hash_get(ht, "expires", AXIS2_HASH_KEY_STRING);
+ /* Free the session hash table entries, because session entries are already in the
+ * session database.
+ */
+ for(hi = axutil_hash_first(ht, env); hi; hi = axutil_hash_next(env, hi))
+ {
+ axis2_char_t *name = NULL;
+ axis2_char_t *value = NULL;
+
+ axutil_hash_this(hi, &key, NULL, &val);
+ name = (axis2_char_t *) key;
+ value = (axis2_char_t *) val;
+ if(name)
+ {
+ AXIS2_FREE(env->allocator, name);
+ }
+ if(value)
+ {
+ AXIS2_FREE(env->allocator, value);
+ }
+ }
}
header_value = AXIS2_MALLOC(env->allocator, 256 * sizeof(axis2_char_t));
sprintf(header_value, "ID=%s; expires=%s;", session_id, time_str);
+ /* Free the session hash table here */
+ axutil_hash_free(ht, env);
AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_http_transport_utils_get_session");
return header_value;
}
@@ -3651,8 +3679,8 @@ axis2_http_transport_utils_set_session(
}
axutil_hash_free(ht, env);
}
-
- property = axutil_property_create_with_args(env, 0, AXIS2_TRUE, 0, ht);
+ /* session hash table does not belong to property.*/
+ property = axutil_property_create_with_args(env, AXIS2_SCOPE_REQUEST, AXIS2_FALSE, 0, ht);
axis2_msg_ctx_set_property(msg_ctx, env, AXIS2_TRANSPORT_SESSION_TABLE, property);
AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_http_tranpsport_utils_set_session");
}