axis-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billblo...@apache.org
Subject svn commit: r1831296 - in /axis/axis2/c/core/trunk/util/test: allocator/allocator_test.cc date_time/date_time_test.cc duration/duration_test.cc string_util/string_util_test.cc uri/uri_test.cc util/test_thread.cc util/test_util.cc utils/utils_test.cc
Date Thu, 10 May 2018 02:52:22 GMT
Author: billblough
Date: Thu May 10 02:52:22 2018
New Revision: 1831296

URL: http://svn.apache.org/viewvc?rev=1831296&view=rev
Log:
Fix memory leaks in util tests

Modified:
    axis/axis2/c/core/trunk/util/test/allocator/allocator_test.cc
    axis/axis2/c/core/trunk/util/test/date_time/date_time_test.cc
    axis/axis2/c/core/trunk/util/test/duration/duration_test.cc
    axis/axis2/c/core/trunk/util/test/string_util/string_util_test.cc
    axis/axis2/c/core/trunk/util/test/uri/uri_test.cc
    axis/axis2/c/core/trunk/util/test/util/test_thread.cc
    axis/axis2/c/core/trunk/util/test/util/test_util.cc
    axis/axis2/c/core/trunk/util/test/utils/utils_test.cc

Modified: axis/axis2/c/core/trunk/util/test/allocator/allocator_test.cc
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/util/test/allocator/allocator_test.cc?rev=1831296&r1=1831295&r2=1831296&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/util/test/allocator/allocator_test.cc (original)
+++ axis/axis2/c/core/trunk/util/test/allocator/allocator_test.cc Thu May 10 02:52:22 2018
@@ -60,7 +60,7 @@ TEST_F(TestAllocator, test_base64)
     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 @@ TEST_F(TestAllocator, test_base64)
 
     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 @@ TEST_F(TestAllocator, test_base64)
     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);
 }
 

Modified: axis/axis2/c/core/trunk/util/test/date_time/date_time_test.cc
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/util/test/date_time/date_time_test.cc?rev=1831296&r1=1831295&r2=1831296&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/util/test/date_time/date_time_test.cc (original)
+++ axis/axis2/c/core/trunk/util/test/date_time/date_time_test.cc Thu May 10 02:52:22 2018
@@ -122,6 +122,9 @@ TEST_F(TestDateTime, test_date_time) {
         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);
    }
 }
 

Modified: axis/axis2/c/core/trunk/util/test/duration/duration_test.cc
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/util/test/duration/duration_test.cc?rev=1831296&r1=1831295&r2=1831296&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/util/test/duration/duration_test.cc (original)
+++ axis/axis2/c/core/trunk/util/test/duration/duration_test.cc Thu May 10 02:52:22 2018
@@ -107,6 +107,8 @@ TEST_F(TestDuration, test_duration) {
     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

Modified: axis/axis2/c/core/trunk/util/test/string_util/string_util_test.cc
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/util/test/string_util/string_util_test.cc?rev=1831296&r1=1831295&r2=1831296&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/util/test/string_util/string_util_test.cc (original)
+++ axis/axis2/c/core/trunk/util/test/string_util/string_util_test.cc Thu May 10 02:52:22
2018
@@ -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 @@ class TestString: public ::testing::Test
 };
 
 
-/** @brief test string 
- *  tokenize a string  
+/** @brief test string
+ *  tokenize a string
  */
 
 TEST_F(TestString, test_string)
@@ -69,7 +69,7 @@ TEST_F(TestString, test_string)
     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 @@ TEST_F(TestString, test_string)
     {
         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);
+
+
 }

Modified: axis/axis2/c/core/trunk/util/test/uri/uri_test.cc
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/util/test/uri/uri_test.cc?rev=1831296&r1=1831295&r2=1831296&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/util/test/uri/uri_test.cc (original)
+++ axis/axis2/c/core/trunk/util/test/uri/uri_test.cc Thu May 10 02:52:22 2018
@@ -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 @@ class TestURI: public ::testing::Test
 
 };
 
-/** @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 @@ TEST_F(TestURI, test_uri)
     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 @@ TEST_F(TestURI, test_uri)
 
     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);
 }

Modified: axis/axis2/c/core/trunk/util/test/util/test_thread.cc
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/util/test/util/test_thread.cc?rev=1831296&r1=1831295&r2=1831296&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/util/test/util/test_thread.cc (original)
+++ axis/axis2/c/core/trunk/util/test/util/test_thread.cc Thu May 10 02:52:22 2018
@@ -149,6 +149,7 @@ test_axutil_thread_detach(
      */
     rv = axutil_thread_detach(t3);
     ASSERT_EQ(rv, AXIS2_FAILURE);
+    AXIS2_FREE(allocator, attr);
  }
 
 void
@@ -170,6 +171,7 @@ test_axutil_thread_detach2(
      */
     rv = axutil_thread_detach(t4);
     ASSERT_EQ(rv, AXIS2_SUCCESS);
+    AXIS2_FREE(allocator, attr);
 }
 
 void

Modified: axis/axis2/c/core/trunk/util/test/util/test_util.cc
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/util/test/util/test_util.cc?rev=1831296&r1=1831295&r2=1831296&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/util/test/util/test_util.cc (original)
+++ axis/axis2/c/core/trunk/util/test/util/test_util.cc Thu May 10 02:52:22 2018
@@ -144,6 +144,7 @@ TEST_F(TestUtil, test_axutil_dir_handler
         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 @@ TEST_F(TestUtil, test_axutil_dir_handler
     printf
         ("----end of test_axutil_dir_handler_list_service_or_module_dirs----\n");
 
+    AXIS2_FREE(m_env->allocator, pathname);
 }
 
 /**
@@ -176,6 +178,7 @@ TEST_F(TestUtil, test_array_list)
 
     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 @@ TEST_F(TestUtil, test_array_list)
 
     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 @@ TEST_F(TestUtil, test_array_list)
     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);
 }
 
 

Modified: axis/axis2/c/core/trunk/util/test/utils/utils_test.cc
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/util/test/utils/utils_test.cc?rev=1831296&r1=1831295&r2=1831296&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/util/test/utils/utils_test.cc (original)
+++ axis/axis2/c/core/trunk/util/test/utils/utils_test.cc Thu May 10 02:52:22 2018
@@ -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 @@ class TestUtils: public ::testing::Test
 };
 
 
-/** @brief test utils 
- *  test quote string  
+/** @brief test utils
+ *  test quote string
  */
 
 TEST_F(TestUtils, test_utils)
@@ -63,8 +63,10 @@ TEST_F(TestUtils, test_utils)
     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, "&lt;root&gt;This is a &amp; in xml string&lt;/root&gt;");
+    AXIS2_FREE(m_allocator, quote_string);
     hexit = axutil_hexit(c);
     ASSERT_EQ(hexit, 12);
 }



Mime
View raw message