Add dbus_message_unref() to avoid memory leak 97/257097/3
authorsooyeon.kim <sooyeon.kim@samsung.com>
Mon, 19 Apr 2021 09:05:19 +0000 (18:05 +0900)
committersooyeon.kim <sooyeon.kim@samsung.com>
Mon, 19 Apr 2021 10:46:22 +0000 (19:46 +0900)
Change-Id: Ie9398d91244e804a40569bf5de7f61cb62d0cd79
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
client/stt_dbus.c

index 39287f1..40d9065 100644 (file)
@@ -424,6 +424,7 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
 
                                dbus_connection_flush(g_conn_listener);
                                dbus_message_unref(reply);
+                               reply = NULL;
                        } else {
                                SLOG(LOG_ERROR, TAG_STTC, ">>>> stt get hello : fail to create reply message");
                        }
@@ -641,11 +642,13 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                else {
                        SLOG(LOG_DEBUG, TAG_STTC, "Message is NOT valid");
                        dbus_message_unref(msg);
+                       msg = NULL;
                        break;
                }
 
                /* free the message */
                dbus_message_unref(msg);
+               msg = NULL;
        } /* while */
 
        return ECORE_CALLBACK_RENEW;
@@ -943,6 +946,7 @@ int stt_dbus_request_hello(int uid)
        if (g_conn_sender) {
                result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_short_time, &err);
                dbus_message_unref(msg);
+               msg = NULL;
                if (dbus_error_is_set(&err)) {
                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Get arguments error (%s)", err.message);
                        dbus_error_free(&err);
@@ -950,6 +954,7 @@ int stt_dbus_request_hello(int uid)
 
                if (NULL != result_msg) {
                        dbus_message_unref(result_msg);
+                       result_msg = NULL;
 
                        if (dbus_error_is_set(&err)) {
                                //LCOV_EXCL_START
@@ -1011,6 +1016,7 @@ int stt_dbus_request_initialize(int uid, bool* silence_supported, bool* credenti
        if (g_conn_sender) {
                result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
                dbus_message_unref(msg);
+               msg = NULL;
                if (dbus_error_is_set(&err)) {
                        //LCOV_EXCL_START
                        SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1045,6 +1051,8 @@ int stt_dbus_request_initialize(int uid, bool* silence_supported, bool* credenti
                                stt_client_s* client = stt_client_get_by_uid(uid);
                                if (NULL == client) {
                                        SLOG(LOG_ERROR, TAG_STTC, "Fail to get STT client");
+                                       dbus_message_unref(result_msg);
+                                       result_msg = NULL;
                                        return STT_ERROR_OPERATION_FAILED;
                                }
 
@@ -1059,6 +1067,8 @@ int stt_dbus_request_initialize(int uid, bool* silence_supported, bool* credenti
                                        if (dbus_error_is_set(&err)) {
                                                SLOG(LOG_ERROR, TAG_STTC, "Match Error (%s)", err.message);
                                                dbus_error_free(&err);
+                                               dbus_message_unref(result_msg);
+                                               result_msg = NULL;
                                                return STT_ERROR_OPERATION_FAILED;
                                        }
                                }
@@ -1067,6 +1077,7 @@ int stt_dbus_request_initialize(int uid, bool* silence_supported, bool* credenti
                        }
 
                        dbus_message_unref(result_msg);
+                       result_msg = NULL;
                } else {
                        SLOG(LOG_ERROR, TAG_STTC, "<<<< Result message is NULL"); //LCOV_EXCL_LINE
                        stt_dbus_reconnect();
@@ -1077,6 +1088,11 @@ int stt_dbus_request_initialize(int uid, bool* silence_supported, bool* credenti
                result = STT_ERROR_OPERATION_FAILED;
        }
 
+       if (msg != NULL) {
+               dbus_message_unref(msg);
+               msg = NULL;
+       }
+
        return result;
 }
 
@@ -1121,6 +1137,7 @@ int stt_dbus_request_finalize(int uid)
 
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_short_time, &err);
        dbus_message_unref(msg);
+       msg = NULL;
        if (dbus_error_is_set(&err)) {
                //LCOV_EXCL_START
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1142,6 +1159,7 @@ int stt_dbus_request_finalize(int uid)
                }
 
                dbus_message_unref(result_msg);
+               result_msg = NULL;
 
                if (0 == result) {
                        SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt finalize : result = %d", result);
@@ -1189,6 +1207,7 @@ int stt_dbus_request_set_current_engine(int uid, const char* engine_id, bool* si
 
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
+       msg = NULL;
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
                dbus_error_free(&err);
@@ -1214,6 +1233,7 @@ int stt_dbus_request_set_current_engine(int uid, const char* engine_id, bool* si
                }
 
                dbus_message_unref(result_msg);
+               result_msg = NULL;
 
                if (0 == result) {
                        SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set engine : result = %d , silence(%d), credential(%d)",
@@ -1266,6 +1286,7 @@ int stt_dbus_request_check_app_agreed(int uid, const char* appid, bool* value)
 
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
+       msg = NULL;
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
                dbus_error_free(&err);
@@ -1283,6 +1304,7 @@ int stt_dbus_request_check_app_agreed(int uid, const char* appid, bool* value)
                        result = STT_ERROR_OPERATION_FAILED;
                }
                dbus_message_unref(result_msg);
+               result_msg = NULL;
 
                if (0 == result) {
                        *value = (bool)available;
@@ -1332,6 +1354,7 @@ int stt_dbus_request_get_support_langs(int uid, stt_h stt, stt_supported_languag
 
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
+       msg = NULL;
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
                dbus_error_free(&err);
@@ -1375,6 +1398,7 @@ int stt_dbus_request_get_support_langs(int uid, stt_h stt, stt_supported_languag
                        }
                }
                dbus_message_unref(result_msg);
+               result_msg = NULL;
        } else {
                SLOG(LOG_ERROR, TAG_STTC, "<<<< stt get support languages : result message is NULL");
                stt_dbus_reconnect();
@@ -1419,6 +1443,7 @@ int stt_dbus_request_get_default_lang(int uid, char** language)
 
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
+       msg = NULL;
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
                dbus_error_free(&err);
@@ -1436,6 +1461,7 @@ int stt_dbus_request_get_default_lang(int uid, char** language)
                        result = STT_ERROR_OPERATION_FAILED;
                }
                dbus_message_unref(result_msg);
+               result_msg = NULL;
 
                if (0 == result) {
                        *language = strdup(temp_lang);
@@ -1492,6 +1518,7 @@ int stt_dbus_request_set_private_data(int uid, const char* key, const char* data
 
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
+       msg = NULL;
        if (dbus_error_is_set(&err)) {
                //LCOV_EXCL_START
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1512,6 +1539,7 @@ int stt_dbus_request_set_private_data(int uid, const char* key, const char* data
                        //LCOV_EXCL_STOP
                }
                dbus_message_unref(result_msg);
+               result_msg = NULL;
 
                if (0 == result) {
                        SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set private data : result = %d", result);
@@ -1565,6 +1593,7 @@ int stt_dbus_request_get_private_data(int uid, const char* key, char** data)
 
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
+       msg = NULL;
        if (dbus_error_is_set(&err)) {
                //LCOV_EXCL_START
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1587,6 +1616,7 @@ int stt_dbus_request_get_private_data(int uid, const char* key, char** data)
                        //LCOV_EXCL_STOP
                }
                dbus_message_unref(result_msg);
+               result_msg = NULL;
 
                if (0 == result) {
                        SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt get private data : result = %d", result);
@@ -1643,6 +1673,7 @@ int stt_dbus_request_is_recognition_type_supported(int uid, const char* type, bo
 
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
+       msg = NULL;
        if (dbus_error_is_set(&err)) {
                //LCOV_EXCL_START
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1664,6 +1695,7 @@ int stt_dbus_request_is_recognition_type_supported(int uid, const char* type, bo
                        //LCOV_EXCL_STOP
                }
                dbus_message_unref(result_msg);
+               result_msg = NULL;
 
                if (0 == result) {
                        *support = (bool)result_support;
@@ -1715,6 +1747,7 @@ int stt_dbus_request_set_start_sound(int uid, const char* file)
 
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
+       msg = NULL;
        if (dbus_error_is_set(&err)) {
                //LCOV_EXCL_START
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1735,6 +1768,7 @@ int stt_dbus_request_set_start_sound(int uid, const char* file)
                        //LCOV_EXCL_STOP
                }
                dbus_message_unref(result_msg);
+               result_msg = NULL;
 
                if (0 == result) {
                        SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set start sound : result = %d", result);
@@ -1779,6 +1813,7 @@ int stt_dbus_request_unset_start_sound(int uid)
 
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
+       msg = NULL;
        if (dbus_error_is_set(&err)) {
                //LCOV_EXCL_START
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1799,6 +1834,7 @@ int stt_dbus_request_unset_start_sound(int uid)
                        //LCOV_EXCL_STOP
                }
                dbus_message_unref(result_msg);
+               result_msg = NULL;
 
                if (0 == result) {
                        SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt unset start sound : result = %d", result);
@@ -1849,6 +1885,7 @@ int stt_dbus_request_set_stop_sound(int uid, const char* file)
 
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
+       msg = NULL;
        if (dbus_error_is_set(&err)) {
                //LCOV_EXCL_START
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1869,6 +1906,7 @@ int stt_dbus_request_set_stop_sound(int uid, const char* file)
                        //LCOV_EXCL_STOP
                }
                dbus_message_unref(result_msg);
+               result_msg = NULL;
 
                if (0 == result) {
                        SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt set stop sound : result = %d", result);
@@ -1913,6 +1951,7 @@ int stt_dbus_request_unset_stop_sound(int uid)
 
        result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err);
        dbus_message_unref(msg);
+       msg = NULL;
        if (dbus_error_is_set(&err)) {
                //LCOV_EXCL_START
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Send Error (%s)", err.message);
@@ -1933,6 +1972,7 @@ int stt_dbus_request_unset_stop_sound(int uid)
                        //LCOV_EXCL_STOP
                }
                dbus_message_unref(result_msg);
+               result_msg = NULL;
 
                if (0 == result) {
                        SLOG(LOG_DEBUG, TAG_STTC, "<<<< stt unset stop sound : result = %d", result);
@@ -1997,6 +2037,8 @@ int stt_dbus_request_start(int uid, const char* lang, const char* type, int sile
                                        free(temp);
                                        temp = NULL;
                        }
+                       dbus_message_unref(msg);
+                       msg = NULL;
                        return STT_ERROR_OUT_OF_MEMORY;
                        //LCOV_EXCL_STOP
                } else {
@@ -2004,6 +2046,7 @@ int stt_dbus_request_start(int uid, const char* lang, const char* type, int sile
                }
 
                dbus_message_unref(msg);
+               msg = NULL;
 
        } else {
                SLOG(LOG_WARN, TAG_STTC, "[WARN] dbus connection handle is null (%p)", g_conn_sender); //LCOV_EXCL_LINE
@@ -2011,6 +2054,8 @@ int stt_dbus_request_start(int uid, const char* lang, const char* type, int sile
                                free(temp);
                                temp = NULL;
                }
+               dbus_message_unref(msg);
+               msg = NULL;
                return STT_ERROR_OPERATION_FAILED;
        }
 
@@ -2088,6 +2133,8 @@ int stt_dbus_request_stop(int uid)
                if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
                        //LCOV_EXCL_START
                        SLOG(LOG_ERROR, TAG_STTC, "[Dbus ERROR] <<<< stt stop message : Out Of Memory !");
+                       dbus_message_unref(msg);
+                       msg = NULL;
                        return STT_ERROR_OUT_OF_MEMORY;
                        //LCOV_EXCL_STOP
                } else {
@@ -2095,8 +2142,11 @@ int stt_dbus_request_stop(int uid)
                }
 
                dbus_message_unref(msg);
+               msg = NULL;
        } else {
                SLOG(LOG_WARN, TAG_STTC, "[WARN] dbus connection handle is null (%p)", g_conn_sender);
+               dbus_message_unref(msg);
+               msg = NULL;
                return STT_ERROR_OPERATION_FAILED;
        }
 
@@ -2170,6 +2220,8 @@ int stt_dbus_request_cancel(int uid)
                if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
                        //LCOV_EXCL_START
                        SLOG(LOG_ERROR, TAG_STTC, "[Dbus ERROR] <<<< stt stop message : Out Of Memory !");
+                       dbus_message_unref(msg);
+                       msg = NULL;
                        return STT_ERROR_OUT_OF_MEMORY;
                        //LCOV_EXCL_STOP
                } else {
@@ -2177,8 +2229,11 @@ int stt_dbus_request_cancel(int uid)
                }
 
                dbus_message_unref(msg);
+               msg = NULL;
        } else {
                SLOG(LOG_WARN, TAG_STTC, "[WARN] dbus connection handle is null (%p)", g_conn_sender);
+               dbus_message_unref(msg);
+               msg = NULL;
                return STT_ERROR_OPERATION_FAILED;
        }
 
@@ -2275,19 +2330,23 @@ int stt_dbus_request_start_file(int uid, const char* lang, const char* type, int
                                free(temp);
                                temp = NULL;
                        }
+                       dbus_message_unref(msg);
+                       msg = NULL;
                        return STT_ERROR_OUT_OF_MEMORY;
                } else {
                        dbus_connection_flush(g_conn_sender);
                }
 
                dbus_message_unref(msg);
-
+               msg = NULL;
        } else {
                SLOG(LOG_WARN, TAG_STTC, "[WARN] dbus connection handle is null (%p)", g_conn_sender);
                if (NULL != temp) {
                                free(temp);
                                temp = NULL;
                }
+               dbus_message_unref(msg);
+               msg = NULL;
                return STT_ERROR_OPERATION_FAILED;
        }
 
@@ -2325,14 +2384,19 @@ int stt_dbus_request_cancel_file(int uid)
 
                if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
                        SLOG(LOG_ERROR, TAG_STTC, "[Dbus ERROR] <<<< stt stop message : Out Of Memory !");
+                       dbus_message_unref(msg);
+                       msg = NULL;
                        return STT_ERROR_OUT_OF_MEMORY;
                } else {
                        dbus_connection_flush(g_conn_sender);
                }
 
                dbus_message_unref(msg);
+               msg = NULL;
        } else {
                SLOG(LOG_WARN, TAG_STTC, "[WARN] dbus connection handle is null (%p)", g_conn_sender);
+               dbus_message_unref(msg);
+               msg = NULL;
                return STT_ERROR_OPERATION_FAILED;
        }