Fix issue detected by static analysis tool 03/312903/2
authorJihoon Kim <jihoon48.kim@samsung.com>
Mon, 17 Jun 2024 06:38:04 +0000 (15:38 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Mon, 17 Jun 2024 07:09:12 +0000 (16:09 +0900)
The pointer returned by operator new can't be null, but it's compared with null at websocket.cpp:718.

Change-Id: I6f4892be9d85d2bce6154a60d3c7f96a923ada4e
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/sclcoreui.cpp
src/websocket.cpp

index b6a349218c5d928ea6e96b1def1a6c8fa68ded16..5f2a793c9bcb20e75f99daa223cfcf0e63e63a69 100644 (file)
@@ -43,10 +43,13 @@ sclboolean CSCLCoreUI::init()
     sclboolean ret = FALSE;
     if (m_impl == NULL) {
         /* There could be other backend implementations.. */
-        m_impl = new CSCLCoreUIEFL;
-        if (m_impl) {
+        try {
+            m_impl = new CSCLCoreUIEFL;
             ret = m_impl->init();
         }
+        catch (const std::bad_alloc& e) {
+            LOGE("bad alloc");
+        }
     }
     return ret;
 }
index d84a83fc7f04cd73ffa4061eaa6046b4de2bc56d..4e8e4e965551e7145d66793c8f52a5e1928fc083 100644 (file)
@@ -714,12 +714,14 @@ void CWebHelperAgentWebSocket::on_get_imdata(char **buf, unsigned int *len)
         ISE_MESSAGE_COMMAND_STRINGS[ISE_MESSAGE_COMMAND_GET_IMDATA], values)) {
             if (values.size() > 0 && buf && len) {
                 int string_length = values.at(0).length();
-                (*buf) = new char[string_length + 1];
-                if (*buf) {
+                try {
+                    (*buf) = new char[string_length + 1];
                     strncpy(*buf, values.at(0).c_str(), string_length);
                     /* Make sure this is a null-terminated string */
                     *(*buf + string_length) = '\0';
                     *len = string_length;
+                } catch (const std::bad_alloc& e) {
+                    LOGE("Bad alloc");
                 }
             }
     } else {