From 56355fb34d9d156f388aa0448cfe902fc1d8bcb7 Mon Sep 17 00:00:00 2001 From: Krzysztof Opasiak Date: Thu, 15 Dec 2016 11:47:26 +0100 Subject: libusbgx: Add usbg_free_config_strs() This is a first step to get rid of static buffers from usbg_config_strs. This function should be called to release memory allocated for configuration string. Signed-off-by: Krzysztof Opasiak --- examples/show-gadgets.c | 2 ++ include/usbg/usbg.h | 10 ++++++++++ src/usbg_schemes_libconfig.c | 2 ++ tests/test.c | 2 ++ 4 files changed, 16 insertions(+) diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c index e56fd4c..a7e593e 100644 --- a/examples/show-gadgets.c +++ b/examples/show-gadgets.c @@ -238,6 +238,8 @@ void show_config(usbg_config *c) fprintf(stdout, " configuration\t%s\n", c_strs.configuration); + usbg_free_config_strs(&c_strs); + usbg_for_each_binding(b, c) { bname = usbg_get_binding_name(b); f = usbg_get_binding_target(b); diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h index 180a265..241d987 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -807,6 +807,16 @@ extern int usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes); extern int usbg_get_config_strs(usbg_config *c, int lang, struct usbg_config_strs *c_strs); +/** + * @brief Free configuration strings + * @details This function releases the memory allocated for strings + * not for struct usbg_config_strs itself. + * @param c_strs Strings to be released + */ +static inline void usbg_free_config_strs(struct usbg_config_strs *c_strs) +{ +} + /** * @brief Set the USB configuration strings * @param c Pointer to configuration diff --git a/src/usbg_schemes_libconfig.c b/src/usbg_schemes_libconfig.c index dcf6aeb..b9b8e35 100644 --- a/src/usbg_schemes_libconfig.c +++ b/src/usbg_schemes_libconfig.c @@ -138,6 +138,8 @@ static int usbg_export_config_strs_lang(usbg_config *c, char *lang_str, cfg_ret = config_setting_set_string(node, strs.configuration); + usbg_free_config_strs(&strs); + ret = cfg_ret == CONFIG_TRUE ? USBG_SUCCESS : USBG_ERROR_OTHER_ERROR; out: return ret; diff --git a/tests/test.c b/tests/test.c index 1b86324..0e91d3e 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1656,9 +1656,11 @@ static void test_set_config_string(void **state) static void try_get_config_strs(usbg_config *c, struct test_config *tc) { struct usbg_config_strs strs; + push_config_strs(tc, LANG_US_ENG, tc->strs); usbg_get_config_strs(c, LANG_US_ENG, &strs); assert_string_equal(tc->strs->configuration, strs.configuration); + usbg_free_config_strs(&strs); } /** -- cgit v1.2.3