Allocate memory for output command list handle 38/261538/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Tue, 20 Jul 2021 09:34:00 +0000 (18:34 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Wed, 21 Jul 2021 02:19:31 +0000 (11:19 +0900)
'vc_get_system_command_list()' should return system command list with memory for handle for this
list. However previous code does not allocate memory.

This patch allocates new memory for output command list handle. System commands would be included
this new handle.
And also, this patch fixes the description of 'vc_get_system_command_list()' to deallocate memory
using 'vc_cmd_list_destroy()'.

Change-Id: Ie9d474d2115681b27c7f51f4da3f5487e7109eca
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/vc.c
include/voice_control.h

index 2cb5930f863a06022da5eed9653df2eb303d6bc4..a2691c0e17e3c5d44227c116e6bee39297818ff4 100644 (file)
@@ -934,6 +934,7 @@ int vc_get_system_command_list(vc_cmd_list_h* vc_sys_cmd_list)
                SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
                return VC_ERROR_INVALID_PARAMETER;
        }
+       *vc_sys_cmd_list = NULL;
 
        vc_state_e state;
        if (0 != vc_client_get_client_state(g_vc, &state)) {
@@ -995,23 +996,31 @@ int vc_get_system_command_list(vc_cmd_list_h* vc_sys_cmd_list)
                return VC_ERROR_OPERATION_FAILED;
        }
 
-       vc_cmd_list_s* list = NULL;
-       list = (vc_cmd_list_s*)(*vc_sys_cmd_list);
        if (true == is_sys_cmd_valid) {
+               vc_cmd_list_s* list = NULL;
+               ret = vc_cmd_list_create((vc_cmd_list_h*)&list);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to create command list"); //LCOV_EXCL_LINE
+                       return ret;
+               }
+
                ret = vc_cmd_parser_get_commands(mgr_pid, VC_COMMAND_TYPE_SYSTEM, &(list->list));
                if (0 != ret) {
                        SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get parsing commands"); //LCOV_EXCL_LINE
+                       vc_cmd_list_destroy((vc_cmd_list_h)list, true);
                        return ret;
                }
+
                ret = vc_cmd_parser_get_commands(mgr_pid, VC_COMMAND_TYPE_SYSTEM_BACKGROUND, &(list->list));
                if (0 != ret) {
                        SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to get parsing commands"); //LCOV_EXCL_LINE
+                       vc_cmd_list_destroy((vc_cmd_list_h)list, true);
                        return ret;
                }
+
                *vc_sys_cmd_list = (vc_cmd_list_h)list;
        } else {
                SLOG(LOG_WARN, TAG_VCC, "[WARNING] No system commands"); //LCOV_EXCL_LINE
-               *vc_sys_cmd_list = NULL;
                return VC_ERROR_NONE;
        }
 
index 69172d2244c6d055ecc3513da1972b49afdbc401..ab80ca2fd2f01372b71ebcb1129c3d9e375003e2 100644 (file)
@@ -245,7 +245,7 @@ int vc_get_service_state(vc_service_state_e* state);
  * @privilege %http://tizen.org/privilege/recorder
  * @remarks In the system command list, there are system commands predefined by product manufacturers. Those commands have the highest priority.
  *          Therefore, the user can not set any commands same with the system commands.
- *          The @a vc_sys_cmd_list must be released using free() when it is no longer required.
+ *          The @a vc_sys_cmd_list must be released using vc_cmd_list_destroy() when it is no longer required.
  * @param[out] vc_sys_cmd_list System command list handle
  * @return @c 0 on success,
  *         otherwise a negative error value
@@ -255,7 +255,7 @@ int vc_get_service_state(vc_service_state_e* state);
  * @retval #VC_ERROR_PERMISSION_DENIED Permission denied
  * @retval #VC_ERROR_NOT_SUPPORTED Not supported
  * @pre The service state should be #VC_SERVICE_STATE_READY.
- * @see vc_unset_command_list()
+ * @see vc_cmd_list_destroy()
  */
 int vc_get_system_command_list(vc_cmd_list_h* vc_sys_cmd_list);