tdm_client: check calloc fail
[platform/core/uifw/libtdm.git] / client / tdm_client.c
index 972ae00..bde7a1f 100644 (file)
@@ -1061,6 +1061,51 @@ tdm_client_output_get_refresh_rate(tdm_client_output *output, unsigned int *refr
 }
 
 tdm_error
+tdm_client_output_get_mode(tdm_client_output *output, unsigned int *width, unsigned int *height)
+{
+       tdm_private_client_output *private_output;
+       tdm_private_client *private_client;
+
+       TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER);
+       TDM_RETURN_VAL_IF_FAIL(width != NULL, TDM_ERROR_INVALID_PARAMETER);
+       TDM_RETURN_VAL_IF_FAIL(height != NULL, TDM_ERROR_INVALID_PARAMETER);
+
+       private_output = (tdm_private_client_output*)output;
+       private_client = private_output->private_client;
+
+       pthread_mutex_lock(&private_client->lock);
+
+       if (private_output->watch_output_changes) {
+               *width = private_output->width;
+               *height = private_output->height;
+               pthread_mutex_unlock(&private_client->lock);
+               return TDM_ERROR_NONE;
+       }
+
+       if (CHECK_WL_PROTOCOL_ERROR(private_client)) {
+               pthread_mutex_unlock(&private_client->lock);
+               return TDM_ERROR_PROTOCOL_ERROR;
+       }
+
+       wl_proxy_set_queue((struct wl_proxy *)private_output->output, private_client->queue);
+       wl_tdm_output_get_mode(private_output->output);
+       wl_display_roundtrip_queue(private_client->display, private_client->queue);
+       wl_proxy_set_queue((struct wl_proxy *)private_output->output, NULL);
+
+       if (CHECK_WL_PROTOCOL_ERROR(private_client)) {
+               pthread_mutex_unlock(&private_client->lock);
+               return TDM_ERROR_PROTOCOL_ERROR;
+       }
+
+       *width = private_output->width;
+       *height = private_output->height;
+
+       pthread_mutex_unlock(&private_client->lock);
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error
 tdm_client_output_get_conn_status(tdm_client_output *output, tdm_output_conn_status *status)
 {
        tdm_private_client_output *private_output;
@@ -1957,7 +2002,7 @@ tdm_client_voutput *
 tdm_client_create_voutput(tdm_client *client, const char *name, tdm_error *error)
 {
        tdm_private_client *private_client;
-       tdm_private_client_output *private_output;
+       tdm_private_client_output *private_output = NULL;
        tdm_private_client_voutput *private_voutput;
        struct wl_proxy *wrapper;
 
@@ -2037,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);
@@ -2102,8 +2148,6 @@ tdm_client_voutput_destroy(tdm_client_voutput *voutput)
                LIST_FOR_EACH_ENTRY_SAFE(cb, cbb, &private_voutput->buffer_list, link) {
                        tbm_surface_h tbm_surface = NULL;
 
-                       if (!cb) continue;
-
                        LIST_DEL(&cb->link);
 
                        tbm_surface = (tbm_surface_h)wl_buffer_get_user_data(cb->wl_buffer);
@@ -2174,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);
        }
 
@@ -2285,6 +2334,8 @@ tdm_client_voutput_remove_commit_handler(tdm_client_voutput *voutput,
                free(h);
 
                pthread_mutex_unlock(&private_client->lock);
+
+               return;
        }
 
        pthread_mutex_unlock(&private_client->lock);