diff options
author | Krzysztof Opasiak <k.opasiak@samsung.com> | 2016-12-15 11:47:26 +0100 |
---|---|---|
committer | Krzysztof Opasiak <k.opasiak@samsung.com> | 2017-03-02 16:56:27 +0100 |
commit | 56355fb34d9d156f388aa0448cfe902fc1d8bcb7 (patch) | |
tree | 74f99504db8aeb0a0cd49ba15afa605eecd282cd | |
parent | 78c45fa80f95bd932dca028b7f248752e030d03e (diff) | |
download | libusbg-56355fb34d9d156f388aa0448cfe902fc1d8bcb7.tar.gz libusbg-56355fb34d9d156f388aa0448cfe902fc1d8bcb7.tar.bz2 libusbg-56355fb34d9d156f388aa0448cfe902fc1d8bcb7.zip |
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 <k.opasiak@samsung.com>
-rw-r--r-- | examples/show-gadgets.c | 2 | ||||
-rw-r--r-- | include/usbg/usbg.h | 10 | ||||
-rw-r--r-- | src/usbg_schemes_libconfig.c | 2 | ||||
-rw-r--r-- | tests/test.c | 2 |
4 files changed, 16 insertions, 0 deletions
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 @@ -808,6 +808,16 @@ 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 * @param lang USB language ID 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); } /** |