tdm_client: check calloc fail
[platform/core/uifw/libtdm.git] / client / tdm_client.c
index d60c6c9..bde7a1f 100644 (file)
@@ -2082,7 +2082,8 @@ tdm_client_create_voutput(tdm_client *client, const char *name, tdm_error *error
        LIST_INITHEAD(&private_voutput->buffer_list);
 
        private_voutput->private_client = private_client;
-       strncpy(private_voutput->name, name, TDM_NAME_LEN);
+       strncpy(private_voutput->name, name, TDM_NAME_LEN - 1);
+       private_voutput->name[TDM_NAME_LEN - 1] = '\0';
 
        private_voutput->wl_voutput = wl_tdm_create_voutput((struct wl_tdm *)wrapper, name);
        wl_proxy_wrapper_destroy(wrapper);
@@ -2217,6 +2218,11 @@ tdm_client_voutput_set_available_modes(tdm_client_voutput *voutput, const tdm_cl
 
        if (count != 0) {
                private_voutput->available_modes.modes = calloc(count, sizeof(tdm_client_output_mode));
+               if (private_voutput->available_modes.modes == NULL) {
+                       private_voutput->available_modes.count = 0;
+                       pthread_mutex_unlock(&private_client->lock);
+                       return TDM_ERROR_OUT_OF_MEMORY;
+               }
                memcpy(private_voutput->available_modes.modes, modes, sizeof(tdm_client_output_mode) * count);
        }
 
@@ -2326,6 +2332,10 @@ tdm_client_voutput_remove_commit_handler(tdm_client_voutput *voutput,
 
                LIST_DEL(&h->link);
                free(h);
+
+               pthread_mutex_unlock(&private_client->lock);
+
+               return;
        }
 
        pthread_mutex_unlock(&private_client->lock);