libsessiond: Add `sessiond_free_user_list()` API function 78/291578/2 accepted/tizen/unified/20230424.033542
authorAdam Michalski <a.michalski2@partner.samsung.com>
Tue, 18 Apr 2023 13:51:34 +0000 (15:51 +0200)
committerAdam Michalski <a.michalski2@partner.samsung.com>
Tue, 18 Apr 2023 14:11:37 +0000 (16:11 +0200)
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

src/library/include/sessiond.h
src/library/src/lib.c
tests/client_example/main.cpp

index 16e5b03..f58c3fa 100644 (file)
@@ -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
index a39319d..2b002af 100644 (file)
@@ -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)))
index f830996..d8643fa 100644 (file)
@@ -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)