tpl_wayland_egl_thread: Added NULL checking when creating thread and thread context. 60/139560/1
authorjoonbum.ko <joonbum.ko@samsung.com>
Wed, 19 Jul 2017 07:18:09 +0000 (16:18 +0900)
committerjoonbum.ko <joonbum.ko@samsung.com>
Wed, 19 Jul 2017 07:18:12 +0000 (16:18 +0900)
 This commit can fix the SVACE issues below.
  [SVACE][WGID][259615] DEREF_OF_NULL.RET.ALLOC
  [SVACE][WGID][264745] DEREF_OF_NULL.RET.ALLOC

Change-Id: Ida8202a811e34ebddb3557abd43daa3610336179
Signed-off-by: joonbum.ko <joonbum.ko@samsung.com>
src/tpl_wayland_egl_thread.c

index 126ce3a..dd9ee0b 100644 (file)
@@ -232,11 +232,24 @@ _twe_thread_tdm_source_destroy(twe_tdm_source *tdm_source)
 twe_thread*
 twe_thread_create(void)
 {
-       twe_thread *thread;
+       twe_thread *thread = NULL;
+
+       thread = calloc(1, sizeof(twe_thread));
+       if (!thread) {
+               TPL_ERR("Failed to allocate twe_thread");
+               return NULL;
+       }
 
        if (!_twe_ctx) {
                GMainContext *context;
+
                _twe_ctx = calloc(1, sizeof(twe_thread_context));
+               if (!_twe_ctx) {
+                       TPL_ERR("Failed to allocate _twe_ctx");
+                       if (thread)
+                               free(thread);
+                       return NULL;
+               }
 
                context = g_main_context_new();
                _twe_ctx->twe_loop = g_main_loop_new(context, FALSE);
@@ -244,9 +257,9 @@ twe_thread_create(void)
 
                _twe_ctx->twe_thread = g_thread_new("twe_thread", _twe_thread_loop,
                                                                                        _twe_ctx);
+               _twe_ctx->ref_cnt = 0;
        }
 
-       thread = calloc(1, sizeof(twe_thread));
        thread->ctx = _twe_ctx;
        _twe_ctx->ref_cnt++;