summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Michalski <a.michalski2@partner.samsung.com>2023-04-18 15:51:34 +0200
committerAdam Michalski <a.michalski2@partner.samsung.com>2023-04-18 16:11:37 +0200
commit7c9c65b3344cae9177830c83b6ace8f70404f070 (patch)
tree43f9b8c036dad4a78d266d1a07c367317026c611
parent34911f815589051d1006480bd670b8dbfb5a933f (diff)
downloadsessiond-7c9c65b3344cae9177830c83b6ace8f70404f070.tar.gz
sessiond-7c9c65b3344cae9177830c83b6ace8f70404f070.tar.bz2
sessiond-7c9c65b3344cae9177830c83b6ace8f70404f070.zip
libsessiond: Add `sessiond_free_user_list()` API functionaccepted/tizen/unified/20230424.033542
Even though it was explicitly stated that one needs to call free() function after `subsession_get_user_list` to deallocate the user list array, the addition of the above routine makes the libsessiond interface more natural, since the API consumer does not need to reach out to a lower layer (glibc) function. Change-Id: I1897c05adf4cd1b759ef0bc7ecf25ef966ac5327
-rw-r--r--src/library/include/sessiond.h12
-rw-r--r--src/library/src/lib.c8
-rw-r--r--tests/client_example/main.cpp2
3 files changed, 19 insertions, 3 deletions
diff --git a/src/library/include/sessiond.h b/src/library/include/sessiond.h
index 16e5b03..f58c3fa 100644
--- a/src/library/include/sessiond.h
+++ b/src/library/include/sessiond.h
@@ -168,13 +168,13 @@ int subsession_switch_user(int session_uid, const subsession_user_t next_user, s
* @retval #SUBSESSION_ERROR_IO_ERROR Internal error occurred
* @retval #SUBSESSION_ERROR_PERMISSION_DENIED Not permitted
* @retval #SUBSESSION_ERROR_NOT_SUPPORTED Not supported
- * @remarks You must free user_list using free()
+ * @remarks You must free user_list using subsession_free_user_list()
*
* subsession_user_t *user_list_ptr;
* int user_count;
* ret = subsession_get_user_list(5001, &user_list_ptr, &user_count);
* ...
- * free(user_list_ptr);
+ * subsession_free_user_list(user_list_ptr);
*
* Also, the user list depends on whether the session ID exists or not. If it
* doesn't, the user list is empty (in particular this is not an error).
@@ -186,6 +186,14 @@ int subsession_switch_user(int session_uid, const subsession_user_t next_user, s
*/
int subsession_get_user_list(int session_uid, subsession_user_t **user_list, int *user_count);
+/*
+ * @brief Frees user list returned by the `subsession_switch_user` function
+ * @since_tizen 7.0
+ *
+ * @param[in] user_list Pointer to an array returned by `subsession_get_user_list`
+ */
+void subsession_free_user_list(subsession_user_t *user_list);
+
/**
* @brief Get currently active subsession ID for given session ID
* @since_tizen 7.0
diff --git a/src/library/src/lib.c b/src/library/src/lib.c
index a39319d..2b002af 100644
--- a/src/library/src/lib.c
+++ b/src/library/src/lib.c
@@ -1030,6 +1030,14 @@ EXPORT_API int subsession_get_user_list(int session_uid, subsession_user_t **use
return ret;
}
+EXPORT_API void subsession_free_user_list(subsession_user_t *user_list)
+{
+ if (!user_list)
+ return;
+
+ free(user_list);
+}
+
EXPORT_API int subsession_get_current_user(int session_uid, subsession_user_t user)
{
return_if(session_uid_is_not_valid(session_uid, current_user_ptr_is_null(user)))
diff --git a/tests/client_example/main.cpp b/tests/client_example/main.cpp
index f830996..d8643fa 100644
--- a/tests/client_example/main.cpp
+++ b/tests/client_example/main.cpp
@@ -327,7 +327,7 @@ template <typename F> struct generic_destructor {
};
struct subsession_user_deleter {
- void operator() (subsession_user_t *p) { free(p); }
+ void operator() (subsession_user_t *p) { subsession_free_user_list(p); }
};
void sessiond_started_callback(void)