summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <freddy77@gmail.com>2021-06-06 06:49:49 +0100
committerFrediano Ziglio <freddy77@gmail.com>2021-06-09 06:55:10 +0100
commitcec6167d1a668db37da70b61e68abec36db883ae (patch)
treecdbb87e4e722dc3205a0e28b06962c829e6089ec
parent75d942e5690fa0181934789d25b8088c4a461f23 (diff)
Provides a usbredirfilter_free function
Makes sure we release resources correctly if the system is using multiple free() implementations. Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
-rw-r--r--tests/filter.c4
-rw-r--r--usbredirparser/usbredirfilter.c7
-rw-r--r--usbredirparser/usbredirfilter.h11
-rw-r--r--usbredirparser/usbredirparser.map6
4 files changed, 22 insertions, 6 deletions
diff --git a/tests/filter.c b/tests/filter.c
index 2ddd4c1..a579be7 100644
--- a/tests/filter.c
+++ b/tests/filter.c
@@ -120,8 +120,8 @@ test_verify_rules_good(void)
filter = usbredirfilter_rules_to_string(rules, count, token_sep, rule_sep);
g_assert_nonnull(filter);
g_assert_cmpstr(expected, ==, filter);
- free(filter);
- free(rules);
+ usbredirfilter_free(filter);
+ usbredirfilter_free(rules);
}
}
diff --git a/usbredirparser/usbredirfilter.c b/usbredirparser/usbredirfilter.c
index 32f05d7..ee8f8b9 100644
--- a/usbredirparser/usbredirfilter.c
+++ b/usbredirparser/usbredirfilter.c
@@ -284,3 +284,10 @@ void usbredirfilter_print(
product, version, rules[i].allow ? "Allow":"Block");
}
}
+
+USBREDIR_VISIBLE
+void usbredirfilter_free(void *ptr)
+{
+ /* for compatibility with 0.10.0 and older this MUST call free() */
+ free(ptr);
+}
diff --git a/usbredirparser/usbredirfilter.h b/usbredirparser/usbredirfilter.h
index 62d4386..eed4b51 100644
--- a/usbredirparser/usbredirfilter.h
+++ b/usbredirparser/usbredirfilter.h
@@ -52,8 +52,8 @@ struct usbredirfilter_rule {
The separators are used as strtok use separators.
On success the rules get returned in rules_ret and rules_count_ret, the
- returned rules array should be freed with free() when the caller is done
- with it.
+ returned rules array should be freed with usbredirfilter_free() when the
+ caller is done with it.
Return value: 0 on success, -ENOMEM when allocating the rules array fails,
or -EINVAL when there is on parsing error.
@@ -63,8 +63,8 @@ int usbredirfilter_string_to_rules(
struct usbredirfilter_rule **rules_ret, int *rules_count_ret);
/* Convert a set of rules back to a string suitable for passing to
- usbredirfilter_string_to_rules(); The returned string must be free()-ed
- by the caller when it is done with it.
+ usbredirfilter_string_to_rules(); The returned string must be
+ usbredirfilter_free()-ed by the caller when it is done with it.
Return value: The string on success, or NULL if the rules fail verification,
or when allocating the string fails.
@@ -133,6 +133,9 @@ int usbredirfilter_verify(
void usbredirfilter_print(
const struct usbredirfilter_rule *rules, int rules_count, FILE *out);
+/* Free memory allocated by the library and returned */
+void usbredirfilter_free(void *ptr);
+
#ifdef __cplusplus
}
#endif
diff --git a/usbredirparser/usbredirparser.map b/usbredirparser/usbredirparser.map
index be01e4c..ab45fed 100644
--- a/usbredirparser/usbredirparser.map
+++ b/usbredirparser/usbredirparser.map
@@ -53,4 +53,10 @@ global:
local:
*;
};
+
+USBREDIRPARSER_0.10.0 {
+global:
+ usbredirfilter_free;
+} USBREDIRPARSER_0.8.0;
+
# .... define new API here using predicted next version number ....