GUACAMOLE-424: Return NULL if guac_common_display allocation fails

Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/commit/f7990af6
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/tree/f7990af6
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/diff/f7990af6

Branch: refs/heads/master
Commit: f7990af6d0c6aac58b705049e52c2587c21b6596
Parents: da0fc1a
Author: itsankoff <ivaylotsanko...@gmail.com>
Authored: Mon Nov 13 14:50:44 2017 +0200
Committer: itsankoff <ivaylotsanko...@gmail.com>
Committed: Mon Nov 13 14:50:44 2017 +0200

----------------------------------------------------------------------
 src/common/display.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-server/blob/f7990af6/src/common/display.c
----------------------------------------------------------------------
diff --git a/src/common/display.c b/src/common/display.c
index 09bf67e..ff70c58 100644
--- a/src/common/display.c
+++ b/src/common/display.c
@@ -99,6 +99,19 @@ static void 
guac_common_display_free_layers(guac_common_display_layer* layers,
 
 }
 
+/**
+ * Allocates a display and a cursor which are used to represent the remote
+ * display and cursor. If the allocation fails then the function returns NULL.
+ *
+ * @param client
+ *     The client owning the cursor.
+ *
+ * @param width
+ *     The desired width of the display.
+ *
+ * @param height
+ *     The desired height of the display.
+ */
 guac_common_display* guac_common_display_alloc(guac_client* client,
         int width, int height) {
 
@@ -107,14 +120,18 @@ guac_common_display* 
guac_common_display_alloc(guac_client* client,
     if (display == NULL)
         return NULL;
 
+    /* Allocate shared cursor */
+    display->cursor = guac_common_cursor_alloc(client);
+    if (display->cursor == NULL) {
+        free(display);
+        return NULL;
+    }
+
     pthread_mutex_init(&display->_lock, NULL);
 
     /* Associate display with given client */
     display->client = client;
 
-    /* Allocate shared cursor */
-    display->cursor = guac_common_cursor_alloc(client);
-
     display->default_surface = guac_common_surface_alloc(client,
             client->socket, GUAC_DEFAULT_LAYER, width, height);
 

Reply via email to