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 2021/11/21 13:43:02 UTC
[celix] branch master updated: Fix memory leak in celix_properties_unset.
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/celix.git
The following commit(s) were added to refs/heads/master by this push:
new 63975be Fix memory leak in celix_properties_unset.
new 50eb07a Merge pull request #379 from PengZheng/fix-properties-memory-leak
63975be is described below
commit 63975bef5f8a09302c5eb0889cdb961a58b55349
Author: PengZheng <ho...@gmail.com>
AuthorDate: Tue Nov 16 11:44:34 2021 +0800
Fix memory leak in celix_properties_unset.
---
libs/utils/private/test/properties_test.cpp | 20 +++++++++++++++++++-
libs/utils/src/properties.c | 2 +-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/libs/utils/private/test/properties_test.cpp b/libs/utils/private/test/properties_test.cpp
index 2fdfe37..613f6ef 100644
--- a/libs/utils/private/test/properties_test.cpp
+++ b/libs/utils/private/test/properties_test.cpp
@@ -165,6 +165,24 @@ TEST(properties, getSet) {
celix_properties_destroy(properties);
}
+TEST(properties, setUnset) {
+ properties = celix_properties_create();
+ char keyA[] = "x";
+ char *keyD = strndup("a", 1);
+ char valueA[] = "1";
+ char *valueD = strndup("4", 1);
+ celix_properties_set(properties, keyA, valueA);
+ celix_properties_setWithoutCopy(properties, keyD, valueD);
+ STRCMP_EQUAL(valueA, celix_properties_get(properties, keyA, NULL));
+ STRCMP_EQUAL(valueD, celix_properties_get(properties, keyD, NULL));
+
+ celix_properties_unset(properties, keyA);
+ celix_properties_unset(properties, keyD);
+ POINTERS_EQUAL(NULL, celix_properties_get(properties, keyA, NULL));
+ POINTERS_EQUAL(NULL, celix_properties_get(properties, "a", NULL));
+ celix_properties_destroy(properties);
+}
+
TEST(properties, longTest) {
properties = celix_properties_create();
@@ -245,4 +263,4 @@ TEST(properties, sizeAndIteratorTest) {
CHECK_EQUAL(4, count);
celix_properties_destroy(props);
-}
\ No newline at end of file
+}
diff --git a/libs/utils/src/properties.c b/libs/utils/src/properties.c
index c735a76..19e215f 100644
--- a/libs/utils/src/properties.c
+++ b/libs/utils/src/properties.c
@@ -398,7 +398,7 @@ void celix_properties_setWithoutCopy(celix_properties_t *properties, char *key,
}
void celix_properties_unset(celix_properties_t *properties, const char *key) {
- char* oldValue = hashMap_remove(properties, key);
+ char* oldValue = hashMap_removeFreeKey(properties, key);
free(oldValue);
}