From 19e694fe68591ee14689cc0da87c7695068262a1 Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Fri, 13 Oct 2023 14:18:24 +0200 Subject: [PATCH] check the malloc --- src/api/api.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api/api.c b/src/api/api.c index 173c511db..ba7bf18b6 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -826,10 +826,12 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z wild -= 1; size_t len = wild - keyexpr._suffix; suffix = z_malloc(len + 1); - memcpy(suffix, keyexpr._suffix, len); - suffix[len] = 0; - keyexpr._suffix = suffix; - _z_keyexpr_set_owns_suffix(&keyexpr, false); + if (suffix != NULL) { + memcpy(suffix, keyexpr._suffix, len); + suffix[len] = 0; + keyexpr._suffix = suffix; + _z_keyexpr_set_owns_suffix(&keyexpr, false); + } } uint16_t id = _z_declare_resource(zs._val, keyexpr); key = _z_rid_with_suffix(id, wild);