You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2023/12/31 00:28:20 UTC
(celix) branch feature/509-remove-cpputests updated (a851bf9f -> 4bb89900)
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a change to branch feature/509-remove-cpputests
in repository https://gitbox.apache.org/repos/asf/celix.git
from a851bf9f Replace array_list with celix_array_list in conan exmpl test
new f2317ed1 Separate celix err ei test to prevent unintentionally init of tss
new 4bb89900 Fix memleak in celix_utils_findIpInSubnet when calling getifaddrs
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
libs/utils/gtest/CMakeLists.txt | 14 +++++++++++++-
libs/utils/gtest/src/IpUtilsErrorInjectionTestSuite.cc | 10 +++-------
libs/utils/src/ip_utils.c | 2 ++
3 files changed, 18 insertions(+), 8 deletions(-)
(celix) 02/02: Fix memleak in celix_utils_findIpInSubnet when calling getifaddrs
Posted by pn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch feature/509-remove-cpputests
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 4bb89900f7773b63d1069a822942e3020b66db71
Author: Pepijn Noltes <pn...@apache.org>
AuthorDate: Sun Dec 31 01:28:11 2023 +0100
Fix memleak in celix_utils_findIpInSubnet when calling getifaddrs
---
libs/utils/gtest/src/IpUtilsErrorInjectionTestSuite.cc | 10 +++-------
libs/utils/src/ip_utils.c | 2 ++
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/libs/utils/gtest/src/IpUtilsErrorInjectionTestSuite.cc b/libs/utils/gtest/src/IpUtilsErrorInjectionTestSuite.cc
index 8bbed74a..9f0dce5b 100644
--- a/libs/utils/gtest/src/IpUtilsErrorInjectionTestSuite.cc
+++ b/libs/utils/gtest/src/IpUtilsErrorInjectionTestSuite.cc
@@ -19,8 +19,6 @@
#include <gtest/gtest.h>
-#include <errno.h>
-
#include "celix_ip_utils.h"
#include "celix_err.h"
@@ -56,25 +54,24 @@ TEST_F(IpUtilsWithErrorInjectionTestSuite, FailToDuplicateStringTest) {
char* ipAddr = nullptr;
//first call to celix_utils_strdup fails
- celix_ei_expect_celix_utils_strdup((void *) &celix_utils_findIpInSubnet, 0, nullptr);
+ celix_ei_expect_celix_utils_strdup((void*)celix_utils_findIpInSubnet, 0, nullptr);
auto status = celix_utils_findIpInSubnet("192.168.1.0/24", &ipAddr);
EXPECT_EQ(status, ENOMEM);
EXPECT_EQ(ipAddr, nullptr);
EXPECT_EQ(errCount++, celix_err_getErrorCount());
//second call to celix_utils_strdup fails (in ifa -> ifa_next loop)
- celix_ei_expect_celix_utils_strdup((void *) &celix_utils_findIpInSubnet, 0, nullptr, 2);
+ celix_ei_expect_celix_utils_strdup((void*)celix_utils_findIpInSubnet, 0, nullptr, 2);
status = celix_utils_findIpInSubnet("127.0.0.1/24", &ipAddr);
EXPECT_EQ(status, ENOMEM);
EXPECT_EQ(ipAddr, nullptr);
EXPECT_EQ(errCount++, celix_err_getErrorCount());
- celix_ei_expect_celix_utils_strdup((void *) &celix_utils_convertIpToUint, 0, nullptr);
+ celix_ei_expect_celix_utils_strdup((void*)celix_utils_convertIpToUint, 0, nullptr);
bool converted;
auto ipAsUint = celix_utils_convertIpToUint("192.168.1.0", &converted);
EXPECT_EQ(ipAsUint, 0);
EXPECT_FALSE(converted);
- EXPECT_EQ(errno, ENOMEM);
EXPECT_EQ(errCount++, celix_err_getErrorCount());
}
@@ -82,6 +79,5 @@ TEST_F(IpUtilsWithErrorInjectionTestSuite, FailToCalledTest) {
celix_ei_expect_calloc((void*)celix_utils_convertUintToIp, 0, nullptr);
auto ip = celix_utils_convertUintToIp(3232235840);
EXPECT_EQ(ip, nullptr);
- EXPECT_EQ(errno, ENOMEM);
EXPECT_EQ(1, celix_err_getErrorCount());
}
diff --git a/libs/utils/src/ip_utils.c b/libs/utils/src/ip_utils.c
index 31638201..12cde0a3 100644
--- a/libs/utils/src/ip_utils.c
+++ b/libs/utils/src/ip_utils.c
@@ -209,6 +209,7 @@ celix_status_t celix_utils_findIpInSubnet(const char* subnetCidrNotation, char**
if (ifIpAsUint >= ipRangeStart && ifIpAsUint <= ipRangeStop && inputPrefix >= ifPrefix) {
char* ip = celix_utils_strdup(if_addr);
if (!ip) {
+ freeifaddrs(ifap);
celix_err_push("Failed to duplicate IP address");
return CELIX_ENOMEM;
}
@@ -216,5 +217,6 @@ celix_status_t celix_utils_findIpInSubnet(const char* subnetCidrNotation, char**
break;
}
}
+ freeifaddrs(ifap);
return CELIX_SUCCESS;
}
(celix) 01/02: Separate celix err ei test to prevent unintentionally init of tss
Posted by pn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch feature/509-remove-cpputests
in repository https://gitbox.apache.org/repos/asf/celix.git
commit f2317ed1dba8cea8d9716e9e0c41fb041e3d719d
Author: Pepijn Noltes <pn...@apache.org>
AuthorDate: Sun Dec 31 01:27:10 2023 +0100
Separate celix err ei test to prevent unintentionally init of tss
---
libs/utils/gtest/CMakeLists.txt | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/libs/utils/gtest/CMakeLists.txt b/libs/utils/gtest/CMakeLists.txt
index 0351ba15..012d2cd3 100644
--- a/libs/utils/gtest/CMakeLists.txt
+++ b/libs/utils/gtest/CMakeLists.txt
@@ -92,12 +92,24 @@ setup_target_for_coverage(test_utils SCAN_DIR ..)
if (EI_TESTS)
+ #Note testing celix err separated, otherwise celix err tss can already be initialized by another util function
+ add_executable(test_celix_err_with_ei
+ src/ErrErrorInjectionTestSuite.cc
+ )
+ target_link_libraries(test_celix_err_with_ei PRIVATE
+ utils_cut
+ Celix::malloc_ei
+ Celix::threads_ei
+ GTest::gtest GTest::gtest_main
+ )
+ add_test(NAME test_celix_err_with_ei COMMAND test_celix_err_with_ei)
+ setup_target_for_coverage(test_celix_err_with_ei SCAN_DIR ..)
+
add_executable(test_utils_with_ei
src/FileUtilsErrorInjectionTestSuite.cc
src/ConvertUtilsErrorInjectionTestSuite.cc
src/IpUtilsErrorInjectionTestSuite.cc
src/ArrayListErrorInjectionTestSuite.cc
- src/ErrErrorInjectionTestSuite.cc
src/PropertiesErrorInjectionTestSuite.cc
src/VersionErrorInjectionTestSuite.cc
src/HashMapErrorInjectionTestSuite.cc