Fix memory leaks in util tests
diff --git a/util/test/allocator/allocator_test.cc b/util/test/allocator/allocator_test.cc
index b678f4e..6e33885 100644
--- a/util/test/allocator/allocator_test.cc
+++ b/util/test/allocator/allocator_test.cc
@@ -60,7 +60,7 @@
axis2_status_t status = AXIS2_FAILURE;
axutil_base64_binary_t *base64_binary;
axutil_base64_binary_t *plain_base64_binary;
- const char *encoded_binary;
+ char *encoded_binary;
unsigned char * get_binary = NULL;
int plain_binary_len, b_len;
unsigned char * plain_binary = NULL;
@@ -77,7 +77,7 @@
plain_base64_binary = axutil_base64_binary_create_with_plain_binary(m_env,
plain_binary,
- plain_binary_len);
+ plain_binary_len);
ASSERT_NE(plain_base64_binary, nullptr);
encoded_binary = axutil_base64_binary_get_encoded_binary(plain_base64_binary, m_env);
@@ -88,25 +88,32 @@
ASSERT_EQ(status, AXIS2_SUCCESS);
plain_binary = axutil_base64_binary_get_plain_binary(base64_binary,m_env,&b_len);
ASSERT_NE(plain_binary, nullptr);
+ ASSERT_NE(plain_binary, buffer);
+ ASSERT_EQ(memcmp(plain_binary, buffer, plain_binary_len), 0);
+
status = axutil_base64_binary_set_encoded_binary(base64_binary,m_env,encoded_binary);
ASSERT_EQ(status, AXIS2_SUCCESS);
get_binary = (unsigned char *) axutil_base64_binary_get_encoded_binary(base64_binary,m_env);
ASSERT_NE(get_binary, nullptr);
+ AXIS2_FREE(m_env->allocator, get_binary);
+ get_binary = NULL;
b_len = axutil_base64_binary_get_encoded_binary_len(base64_binary,m_env);
ASSERT_NE(b_len, 0);
axutil_base64_binary_free(base64_binary, m_env);
- base64_binary = axutil_base64_binary_create_with_encoded_binary(m_env, encoded_binary);
+ base64_binary = axutil_base64_binary_create_with_encoded_binary(m_env, encoded_binary);
ASSERT_NE(base64_binary, nullptr);
if (base64_binary != nullptr)
- {
- int binary_len;
- get_binary = axutil_base64_binary_get_plain_binary(base64_binary,m_env, &binary_len);
- ASSERT_EQ(binary_len, plain_binary_len);
+ {
+ int binary_len;
+ get_binary = axutil_base64_binary_get_plain_binary(base64_binary,m_env, &binary_len);
+ ASSERT_EQ(binary_len, plain_binary_len);
ASSERT_EQ(memcmp(get_binary, plain_binary, plain_binary_len), 0);
axutil_base64_binary_free(base64_binary, m_env);
- }
+ }
- axutil_base64_binary_free(plain_base64_binary, m_env);
+ axutil_base64_binary_free(plain_base64_binary, m_env);
+ AXIS2_FREE(m_env->allocator, encoded_binary);
+ AXIS2_FREE(m_env->allocator, plain_binary);
}
diff --git a/util/test/date_time/date_time_test.cc b/util/test/date_time/date_time_test.cc
index 37d4538..c5aaddb 100644
--- a/util/test/date_time/date_time_test.cc
+++ b/util/test/date_time/date_time_test.cc
@@ -122,6 +122,9 @@
ASSERT_EQ(msec, 799);
axutil_date_time_free(date_time,m_env);
+ AXIS2_FREE(m_allocator, t_str);
+ AXIS2_FREE(m_allocator, d_str);
+ AXIS2_FREE(m_allocator, dt_str);
}
}
diff --git a/util/test/duration/duration_test.cc b/util/test/duration/duration_test.cc
index db28b1d..8a09347 100644
--- a/util/test/duration/duration_test.cc
+++ b/util/test/duration/duration_test.cc
@@ -107,6 +107,8 @@
axutil_duration_free(duration_two, m_env);
axutil_duration_free(duration_three, m_env);
axutil_duration_free(duration_four, m_env);
+ AXIS2_FREE(m_allocator, serialize);
+ AXIS2_FREE(m_allocator, serialize1);
}
/** @brief set values
diff --git a/util/test/string_util/string_util_test.cc b/util/test/string_util/string_util_test.cc
index e1b5a16..2c8ae01 100644
--- a/util/test/string_util/string_util_test.cc
+++ b/util/test/string_util/string_util_test.cc
@@ -1,23 +1,23 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#include <gtest/gtest.h>
-#include <string.h>
+#include <string.h>
#include "../util/create_env.h"
#include <axutil_string_util.h>
#include <axutil_array_list.h>
@@ -52,8 +52,8 @@
};
-/** @brief test string
- * tokenize a string
+/** @brief test string
+ * tokenize a string
*/
TEST_F(TestString, test_string)
@@ -69,7 +69,7 @@
ASSERT_NE(tokenize, nullptr);
token = axutil_array_list_get(tokenize,m_env,4);
ASSERT_NE(token, nullptr);
- ASSERT_STREQ((const char *)token, "string");
+ ASSERT_STREQ((const char *)token, "string");
first_token = axutil_first_token(m_env,in,delim);
ASSERT_NE(first_token, nullptr);
@@ -77,16 +77,34 @@
{
first_token_string = axutil_array_list_get(first_token,m_env,1);
ASSERT_NE(first_token_string, nullptr);
- ASSERT_STREQ((const char *)first_token_string, "is a test string");
+ ASSERT_STREQ((const char *)first_token_string, "is a test string");
+ while(axutil_array_list_size(first_token, m_env)) {
+ token = axutil_array_list_remove(first_token, m_env, 0);
+ AXIS2_FREE(m_allocator, token);
+ }
+ axutil_array_list_free(first_token, m_env);
}
last_token = axutil_last_token(m_env,in,delim);
- ASSERT_NE(last_token, nullptr);
+ ASSERT_NE(last_token, nullptr);
if(last_token)
{
last_token_string = axutil_array_list_get(last_token,m_env,1);
- ASSERT_NE(last_token_string, nullptr);
- ASSERT_STREQ((const char *)last_token_string, "string");
+ ASSERT_NE(last_token_string, nullptr);
+ ASSERT_STREQ((const char *)last_token_string, "string");
+ while(axutil_array_list_size(last_token, m_env)) {
+ token = axutil_array_list_remove(last_token, m_env, 0);
+ AXIS2_FREE(m_allocator, token);
+ }
+ axutil_array_list_free(last_token, m_env);
}
+ while(axutil_array_list_size(tokenize, m_env)) {
+ token = axutil_array_list_remove(tokenize, m_env, 0);
+ AXIS2_FREE(m_allocator, token);
+ }
+
+ axutil_array_list_free(tokenize, m_env);
+
+
}
diff --git a/util/test/uri/uri_test.cc b/util/test/uri/uri_test.cc
index 1204feb..d31013f 100644
--- a/util/test/uri/uri_test.cc
+++ b/util/test/uri/uri_test.cc
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#include <gtest/gtest.h>
@@ -48,8 +48,8 @@
};
-/** @brief test uri
- * * create URI and get the values of it's components
+/** @brief test uri
+ * * create URI and get the values of it's components
* */
TEST_F(TestURI, test_uri)
{
@@ -64,15 +64,15 @@
axutil_uri_t * rel = NULL;
axis2_port_t scheme_port;
axis2_port_t port;
- axis2_char_t * str;
+ axis2_char_t * str;
hostinfo = axutil_uri_parse_hostinfo(m_env,host);
ASSERT_NE(hostinfo, nullptr);
- scheme_port = axutil_uri_port_of_scheme(scheme_str);
+ scheme_port = axutil_uri_port_of_scheme(scheme_str);
ASSERT_NE(scheme_port, 0);
- uri = axutil_uri_parse_string(m_env,uri_str);
+ uri = axutil_uri_parse_string(m_env,uri_str);
ASSERT_NE(uri, nullptr);
str = axutil_uri_get_protocol(uri,m_env);
ASSERT_STREQ(str, "http");
@@ -85,28 +85,33 @@
base = axutil_uri_parse_string(m_env,uri_str_base);
ASSERT_NE(base, nullptr);
- if (base)
+ if (base)
{
str = axutil_uri_to_string(base,m_env,0);
ASSERT_STREQ(str, "http://user:XXXXXXXX@example.com/foo?bar");
+ AXIS2_FREE(m_allocator, str);
}
clone = axutil_uri_clone(uri,m_env);
ASSERT_NE(clone, nullptr);
- if (clone)
+ if (clone)
{
str = axutil_uri_to_string(clone,m_env,0);
ASSERT_STREQ(str, "http://user:XXXXXXXX@example.com/foo?bar#item5");
axutil_uri_free(clone,m_env);
- }
+ AXIS2_FREE(m_allocator, str);
+ }
rel = axutil_uri_resolve_relative(m_env,base,uri);
ASSERT_NE(rel, nullptr);
- if (rel)
+ if (rel)
{
str = axutil_uri_to_string(rel,m_env,0);
ASSERT_STREQ(str, "http://user:XXXXXXXX@example.com/foo?bar#item5");
+ AXIS2_FREE(m_allocator, str);
}
axutil_uri_free(uri,m_env);
+ axutil_uri_free(base, m_env);
+ axutil_uri_free(hostinfo, m_env);
}
diff --git a/util/test/util/test_thread.cc b/util/test/util/test_thread.cc
index 5a73ba4..e639689 100644
--- a/util/test/util/test_thread.cc
+++ b/util/test/util/test_thread.cc
@@ -149,6 +149,7 @@
*/
rv = axutil_thread_detach(t3);
ASSERT_EQ(rv, AXIS2_FAILURE);
+ AXIS2_FREE(allocator, attr);
}
void
@@ -170,6 +171,7 @@
*/
rv = axutil_thread_detach(t4);
ASSERT_EQ(rv, AXIS2_SUCCESS);
+ AXIS2_FREE(allocator, attr);
}
void
diff --git a/util/test/util/test_util.cc b/util/test/util/test_util.cc
index 1096324..f0a06b1 100644
--- a/util/test/util/test_util.cc
+++ b/util/test/util/test_util.cc
@@ -144,6 +144,7 @@
axutil_dir_handler_list_service_or_module_dirs(m_env, pathname);
if (arr_folders == NULL)
{
+ AXIS2_FREE(m_env->allocator, pathname);
printf("List of folders is NULL\n");
return;
}
@@ -160,6 +161,7 @@
printf
("----end of test_axutil_dir_handler_list_service_or_module_dirs----\n");
+ AXIS2_FREE(m_env->allocator, pathname);
}
/**
@@ -176,6 +178,7 @@
axutil_array_list_t *al;
a *entry = NULL;
+ a *tmpentry = NULL;
int size;
al = axutil_array_list_create(m_env, 1);
@@ -208,8 +211,24 @@
entry = (a *) AXIS2_MALLOC(m_env->allocator, sizeof(a));
entry->value = (axis2_char_t*) axutil_strdup(m_env, "value7");
+ size = axutil_array_list_size(al, m_env);
+ ASSERT_EQ(size, 6);
+
+ tmpentry = (a *) axutil_array_list_get(al, m_env, 3);
axutil_array_list_set(al, m_env, 3, (void *) entry);
+ size = axutil_array_list_size(al, m_env);
+ ASSERT_EQ(size, 6);
+ AXIS2_FREE(m_env->allocator, tmpentry->value);
+ AXIS2_FREE(m_env->allocator, tmpentry);
+ tmpentry = NULL;
+
+ tmpentry = (a *) axutil_array_list_get(al, m_env, 2);
axutil_array_list_remove(al, m_env, 2);
+ size = axutil_array_list_size(al, m_env);
+ ASSERT_EQ(size, 5);
+ AXIS2_FREE(m_env->allocator, tmpentry->value);
+ AXIS2_FREE(m_env->allocator, tmpentry);
+ tmpentry = NULL;
entry = (a *) axutil_array_list_get(al, m_env, 0);
ASSERT_STREQ(entry->value, "value1");
@@ -218,6 +237,14 @@
ASSERT_STREQ(entry->value, "value7");
size = axutil_array_list_size(al, m_env);
ASSERT_EQ(size, 5);
+
+ while (size = axutil_array_list_size(al, m_env)) {
+ entry = (a *) axutil_array_list_remove(al, m_env, 0);
+ AXIS2_FREE(m_env->allocator, entry->value);
+ AXIS2_FREE(m_env->allocator, entry);
+ }
+
+ axutil_array_list_free(al, m_env);
}
diff --git a/util/test/utils/utils_test.cc b/util/test/utils/utils_test.cc
index 8cb2d80..f936466 100644
--- a/util/test/utils/utils_test.cc
+++ b/util/test/utils/utils_test.cc
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#include <gtest/gtest.h>
@@ -49,8 +49,8 @@
};
-/** @brief test utils
- * test quote string
+/** @brief test utils
+ * test quote string
*/
TEST_F(TestUtils, test_utils)
@@ -63,8 +63,10 @@
int hexit;
op = axutil_parse_request_url_for_svc_and_op(m_env,request);
ASSERT_NE(op, nullptr);
+ AXIS2_FREE(m_allocator, op);
quote_string = axutil_xml_quote_string(m_env,s,1);
ASSERT_STREQ(quote_string, "<root>This is a & in xml string</root>");
+ AXIS2_FREE(m_allocator, quote_string);
hexit = axutil_hexit(c);
ASSERT_EQ(hexit, 12);
}