@@ -890,6 +890,7 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z
890
890
const z_subscriber_options_t * options ) {
891
891
void * ctx = callback -> context ;
892
892
callback -> context = NULL ;
893
+ char * suffix = NULL ;
893
894
894
895
z_keyexpr_t key = keyexpr ;
895
896
// TODO: Currently, if resource declarations are done over multicast transports, the current protocol definition
@@ -901,17 +902,24 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z
901
902
_z_resource_t * r = _z_get_resource_by_key (zs ._val , & keyexpr );
902
903
if (r == NULL ) {
903
904
char * wild = strpbrk (keyexpr ._suffix , "*$" );
905
+ _Bool do_keydecl = true;
904
906
if (wild != NULL && wild != keyexpr ._suffix ) {
905
907
wild -= 1 ;
906
908
size_t len = wild - keyexpr ._suffix ;
907
- char * suffix = z_malloc (len + 1 );
908
- memcpy (suffix , keyexpr ._suffix , len );
909
- suffix [len ] = 0 ;
910
- keyexpr ._suffix = suffix ;
911
- _z_keyexpr_set_owns_suffix (& keyexpr , true);
909
+ suffix = z_malloc (len + 1 );
910
+ if (suffix != NULL ) {
911
+ memcpy (suffix , keyexpr ._suffix , len );
912
+ suffix [len ] = 0 ;
913
+ keyexpr ._suffix = suffix ;
914
+ _z_keyexpr_set_owns_suffix (& keyexpr , false);
915
+ } else {
916
+ do_keydecl = false;
917
+ }
918
+ }
919
+ if (do_keydecl ) {
920
+ uint16_t id = _z_declare_resource (zs ._val , keyexpr );
921
+ key = _z_rid_with_suffix (id , wild );
912
922
}
913
- uint16_t id = _z_declare_resource (zs ._val , keyexpr );
914
- key = _z_rid_with_suffix (id , wild );
915
923
}
916
924
#if Z_FEATURE_MULTICAST_TRANSPORT == 1
917
925
}
@@ -921,9 +929,12 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z
921
929
if (options != NULL ) {
922
930
subinfo .reliability = options -> reliability ;
923
931
}
932
+ _z_subscriber_t * sub = _z_declare_subscriber (zs ._val , key , subinfo , callback -> call , callback -> drop , ctx );
933
+ if (suffix != NULL ) {
934
+ z_free (suffix );
935
+ }
924
936
925
- return (z_owned_subscriber_t ){
926
- ._value = _z_declare_subscriber (zs ._val , key , subinfo , callback -> call , callback -> drop , ctx )};
937
+ return (z_owned_subscriber_t ){._value = sub };
927
938
}
928
939
929
940
z_owned_pull_subscriber_t z_declare_pull_subscriber (z_session_t zs , z_keyexpr_t keyexpr ,
0 commit comments