From 4c8f6930c70c7ac1a50c0c239c42e45a8be064fb Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 27 Sep 2024 19:29:46 -0700 Subject: [PATCH] GUACAMOLE-377: Restore original NULL returns for alloc failures of streams/objects. --- src/libguac/client.c | 5 +++-- src/libguac/user.c | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libguac/client.c b/src/libguac/client.c index ab8a07c1d..71fa7f763 100644 --- a/src/libguac/client.c +++ b/src/libguac/client.c @@ -128,8 +128,9 @@ guac_stream* guac_client_alloc_stream(guac_client* client) { int stream_index; /* Allocate stream, but refuse to allocate beyond maximum */ - stream_index = guac_pool_next_int_below_or_die(client->__stream_pool, - GUAC_CLIENT_MAX_STREAMS); + stream_index = guac_pool_next_int_below(client->__stream_pool, GUAC_CLIENT_MAX_STREAMS); + if (stream_index < 0) + return NULL; /* Initialize stream with odd index (even indices are user-level) */ allocd_stream = &(client->__output_streams[stream_index]); diff --git a/src/libguac/user.c b/src/libguac/user.c index 160e27478..16baa169f 100644 --- a/src/libguac/user.c +++ b/src/libguac/user.c @@ -108,8 +108,9 @@ guac_stream* guac_user_alloc_stream(guac_user* user) { int stream_index; /* Allocate stream, but refuse to allocate beyond maximum */ - stream_index = guac_pool_next_int_below_or_die(user->__stream_pool, - GUAC_USER_MAX_STREAMS); + stream_index = guac_pool_next_int_below(user->__stream_pool, GUAC_USER_MAX_STREAMS); + if (stream_index < 0) + return NULL; /* Initialize stream with even index (odd indices are client-level) */ allocd_stream = &(user->__output_streams[stream_index]); @@ -139,8 +140,9 @@ guac_object* guac_user_alloc_object(guac_user* user) { int object_index; /* Allocate object, but refuse to allocate beyond maximum */ - object_index = guac_pool_next_int_below_or_die(user->__object_pool, - GUAC_USER_MAX_OBJECTS); + object_index = guac_pool_next_int_below(user->__object_pool, GUAC_USER_MAX_OBJECTS); + if (object_index < 0) + return NULL; /* Initialize object */ allocd_object = &(user->__objects[object_index]);