This is an automated email from the ASF dual-hosted git repository.

pengzheng pushed a commit to branch hotfix/utils_coverity_fix
in repository https://gitbox.apache.org/repos/asf/celix.git

commit be3d43221980de75e72ab0f7f77a9326406f7f84
Author: PengZheng <[email protected]>
AuthorDate: Tue Apr 25 20:43:04 2023 +0800

    Fix Coverity 218468 Resource leak.
---
 libs/utils/gtest/src/VersionRangeTestSuite.cc | 12 +-----------
 libs/utils/src/version_range.c                |  2 ++
 2 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/libs/utils/gtest/src/VersionRangeTestSuite.cc 
b/libs/utils/gtest/src/VersionRangeTestSuite.cc
index 3659b39a..85fa1a7e 100644
--- a/libs/utils/gtest/src/VersionRangeTestSuite.cc
+++ b/libs/utils/gtest/src/VersionRangeTestSuite.cc
@@ -169,16 +169,7 @@ TEST_F(VersionRangeTestSuite, isInRange) {
 
 TEST_F(VersionRangeTestSuite, parse) {
     version_range_pt range = nullptr;
-    version_pt low = (version_pt) calloc(1, sizeof(*low));
-    version_pt high = (version_pt) calloc(1, sizeof(*high));
     char * version = strdup("[1.2.3,7.8.9]");
-    low->major = 1;
-    low->minor = 2;
-    low->micro = 3;
-
-    high->major = 7;
-    high->minor = 8;
-    high->micro = 9;
 
     EXPECT_EQ(CELIX_SUCCESS, versionRange_parse(version, &range));
 
@@ -190,8 +181,7 @@ TEST_F(VersionRangeTestSuite, parse) {
 
     free(version);
 
-    free(high);
-    free(low);
+    EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, versionRange_parse("[2.2.3,a.b.c)", 
&range));
 }
 
 TEST_F(VersionRangeTestSuite, createLdapFilterInclusiveBoth) {
diff --git a/libs/utils/src/version_range.c b/libs/utils/src/version_range.c
index c190ccfe..f03fee94 100644
--- a/libs/utils/src/version_range.c
+++ b/libs/utils/src/version_range.c
@@ -225,6 +225,8 @@ celix_version_range_t* celix_versionRange_parse(const char 
*rangeString) {
                         versionHigh,
                         end ==']'
                 );
+            } else {
+                celix_version_destroy(versionLow);
             }
         }
         free(vhigh);

Reply via email to