Fixed crash in ECS network option. 06/273406/1
authorvarinder.p <varinder.p@samsung.com>
Mon, 28 Mar 2022 18:19:32 +0000 (23:49 +0530)
committerVarinder Pratap Singh <varinder.p@samsung.com>
Tue, 5 Apr 2022 08:29:47 +0000 (13:59 +0530)
Change-Id: I0bc8d1f92cd7c3d667164d5f96663e36619b3158
Signed-off-by: varinder.p <varinder.p@samsung.com>
tizen/src/ecs/ecs.c
tizen/src/ecs/ecs_mon.c

index 7407cc1cbdd1dd1fd053e91821debff471b3254c..72d5d2409445e91a3ab030716361b221116728ee 100644 (file)
@@ -339,6 +339,16 @@ static MonitorQMP *monitor_create(void)
         return NULL;
     }
 
+    monitor_data_init(&mon->common, true, false, false);
+
+    mon->commands = &qmp_commands;
+
+    mon->pretty = true;
+
+    qemu_mutex_init(&mon->qmp_queue_lock);
+    mon->qmp_requests = g_queue_new();
+
+    monitor_list_append(&mon->common);
     return mon;
 }
 
index cb1f132f2414bf9be7f362f5209e39172e7de9f3..eee7998d27ca3e8740e842fb7504cc5abfb18593 100644 (file)
@@ -60,7 +60,7 @@ bool send_monitor_ntf(const char *data, int size)
     ECS__Master master = ECS__MASTER__INIT;
     ECS__MonitorNtf ntf = ECS__MONITOR_NTF__INIT;
 
-    TRACE("data size : %d, data : %s\n", size, data);
+    LOG_INFO("data size : %d, data : %s\n", size, data);
 
     ntf.command = (char *) g_malloc(size + 1);
     memcpy(ntf.command, data, size);
@@ -77,11 +77,11 @@ bool send_monitor_ntf(const char *data, int size)
 
 static void ecs_monitor_flush(Monitor *mon)
 {
-    if (mon && mon->outbuf != NULL) {
+    if (mon->outbuf != NULL) {
         bool ret = send_monitor_ntf(qstring_get_str(mon->outbuf), qstring_get_length(mon->outbuf));
-        qstring_free(mon->outbuf, false);
-        mon->outbuf = NULL;
-        TRACE("ecs_monitor_flush return value of send_monitor_ntf : %d, \n", ret);
+        LOG_INFO("ecs_monitor_flush return value of send_monitor_ntf : %d, \n", ret);
+        qobject_unref(mon->outbuf);
+        mon->outbuf = qstring_new();
     }
 }
 
@@ -95,20 +95,19 @@ static void ecs_monitor_puts(Monitor *mon, const char *str)
         str = "\n";
     }
 
-    LOG_INFO("ecs_monitor_puts  - data: %s", str);
+    LOG_INFO("ecs_monitor_puts  - data: %s\n", str);
 
     for (i = 0; str[i]; i++) {
         c = str[i];
         if (c == '\n') {
-#ifdef _WIN32
+#ifdef CONFIG_WIN32
             qstring_append_chr(mon->outbuf, '\r');
-#endif  // _WIN32     
+#endif  // CONFIG_WIN32     
         }
         qstring_append_chr(mon->outbuf, c);
-        if (c == '\n') {
-            ecs_monitor_flush(mon);
-        }
     }
+
+    ecs_monitor_flush(mon);        
 }
 
 static QDict *build_qmp_error_dict(Error *err)
@@ -220,15 +219,7 @@ static void ecs_monitor_qmp_respond(MonitorQMP *mon, QDict *rsp)
 {
     const QObject *data = QOBJECT(rsp);
     QString *json;
-
-    //Add type in response
-    if (mon->common.outbuf) {
-        qdict_put(rsp, "type", mon->common.outbuf);
-        qstring_free(mon->common.outbuf , false);
-        mon->common.outbuf = NULL;
-    } else {
-        qdict_put_str(rsp, "type", "unknown");
-    }
+    LOG_INFO("ecs_monitor_qmp_respond: qobject_to_json_pretty\n");
 
     json = mon->pretty ? qobject_to_json_pretty(data) : qobject_to_json(data);
     assert(json != NULL);
@@ -239,11 +230,6 @@ static void ecs_monitor_qmp_respond(MonitorQMP *mon, QDict *rsp)
     qobject_unref(json);
 }
 
-static bool ecs_qmp_oob_enabled(MonitorQMP *mon)
-{
-    return mon->capab[QMP_CAPABILITY_OOB];
-}
-
 static void ecs_monitor_qmp_dispatch(MonitorQMP *mon, QObject *req)
 {
     Monitor *old_mon;
@@ -253,7 +239,7 @@ static void ecs_monitor_qmp_dispatch(MonitorQMP *mon, QObject *req)
     old_mon = cur_mon;
     cur_mon = &mon->common;
 
-    rsp = qmp_dispatch(mon->commands, req, ecs_qmp_oob_enabled(mon));
+    rsp = qmp_dispatch(mon->commands, req, true);
 
     cur_mon = old_mon;
 
@@ -282,6 +268,7 @@ void ecs_handle_qmp_command(void *opaque, QObject *req, Error *err)
     Error *local_err = NULL;
     
     assert(!req != !err);
+    assert(mon != NULL);
 
     if (err) {
         local_err = err;
@@ -296,8 +283,7 @@ void ecs_handle_qmp_command(void *opaque, QObject *req, Error *err)
     if (qdict) {
         id = qdict_get(qdict, "id");
         if (qdict_haskey(qdict, "type")) {
-            //store type in outbuf to return in response
-            mon->common.outbuf = qobject_to(QString, qdict_get(qdict, "type"));
+            //TODO: store type in outbuf to return in response
             qdict_del(qdict, "type");
         }
     } /* else will fail qmp_dispatch() */