@@ -71,23 +71,18 @@ static void ot_rpc_cmd_coap_new_message(const struct nrf_rpc_group *group,
71
71
72
72
openthread_api_mutex_lock (openthread_get_default_context ());
73
73
message = otCoapNewMessage (openthread_get_default_instance (), settings );
74
- openthread_api_mutex_unlock (openthread_get_default_context ());
75
-
76
- if (!message ) {
77
- goto out ;
78
- }
79
-
80
74
message_rep = ot_reg_msg_alloc (message );
81
75
82
- if (!message_rep ) {
76
+ if (( message != NULL ) && !message_rep ) {
83
77
/*
84
- * If failed to allocate the message handle, the ownership can't be passed to the
85
- * RPC client. Therefore, free the message.
78
+ * Failed to allocate the message handle, so the ownership can't be passed to
79
+ * the RPC client. Therefore, free the message.
86
80
*/
87
81
otMessageFree (message );
88
82
}
89
83
90
- out :
84
+ openthread_api_mutex_unlock (openthread_get_default_context ());
85
+
91
86
nrf_rpc_rsp_send_uint (group , message_rep );
92
87
}
93
88
@@ -180,7 +175,7 @@ static void ot_rpc_cmd_coap_message_append_uri_path_options(const struct nrf_rpc
180
175
message_rep = nrf_rpc_decode_uint (ctx );
181
176
nrf_rpc_decode_str (ctx , uri , sizeof (uri ));
182
177
183
- if (!nrf_rpc_decode_valid ( ctx )) {
178
+ if (!nrf_rpc_decoding_done_and_check ( group , ctx )) {
184
179
ot_rpc_report_cmd_decoding_error (OT_RPC_CMD_COAP_MESSAGE_APPEND_URI_PATH_OPTIONS );
185
180
return ;
186
181
}
@@ -194,7 +189,6 @@ static void ot_rpc_cmd_coap_message_append_uri_path_options(const struct nrf_rpc
194
189
195
190
openthread_api_mutex_lock (openthread_get_default_context ());
196
191
error = otCoapMessageAppendUriPathOptions (message , uri );
197
- nrf_rpc_cbor_decoding_done (group , ctx );
198
192
openthread_api_mutex_unlock (openthread_get_default_context ());
199
193
200
194
nrf_rpc_rsp_send_uint (group , error );
@@ -455,6 +449,8 @@ static void ot_rpc_coap_resource_handler(void *aContext, otMessage *aMessage,
455
449
message_rep = ot_reg_msg_alloc (aMessage );
456
450
457
451
if (!message_rep ) {
452
+ nrf_rpc_err (- ENOMEM , NRF_RPC_ERR_SRC_SEND , & ot_group ,
453
+ OT_RPC_CMD_COAP_RESOURCE_HANDLER , NRF_RPC_PACKET_TYPE_CMD );
458
454
return ;
459
455
}
460
456
@@ -559,6 +555,8 @@ static void ot_rpc_coap_default_handler(void *aContext, otMessage *aMessage,
559
555
message_rep = ot_reg_msg_alloc (aMessage );
560
556
561
557
if (!message_rep ) {
558
+ nrf_rpc_err (- ENOMEM , NRF_RPC_ERR_SRC_SEND , & ot_group ,
559
+ OT_RPC_CMD_COAP_DEFAULT_HANDLER , NRF_RPC_PACKET_TYPE_CMD );
562
560
return ;
563
561
}
564
562
@@ -606,13 +604,12 @@ static void ot_rpc_coap_response_handler(void *context, otMessage *message,
606
604
struct nrf_rpc_cbor_ctx ctx ;
607
605
size_t cbor_buffer_size = 0 ;
608
606
609
- if (message ) {
610
- message_rep = ot_reg_msg_alloc (message );
611
-
612
- if (!message_rep ) {
613
- return ;
614
- }
615
- }
607
+ message_rep = ot_reg_msg_alloc (message );
608
+ /*
609
+ * Ignore message handle allocation failure. It seems safer to call the client's response
610
+ * handler without the response (which indicates response timeout) than not to call the
611
+ * handler at all and make the client wait for the response indefinitely.
612
+ */
616
613
617
614
cbor_buffer_size += 1 + sizeof (ot_rpc_coap_request_key );
618
615
cbor_buffer_size += 1 + sizeof (ot_msg_key );
@@ -657,12 +654,12 @@ static void ot_rpc_cmd_coap_send_request(const struct nrf_rpc_group *group,
657
654
openthread_api_mutex_lock (openthread_get_default_context ());
658
655
error = otCoapSendRequest (openthread_get_default_instance (), message , & message_info ,
659
656
ot_rpc_coap_response_handler , (void * )request_rep );
660
- openthread_api_mutex_unlock (openthread_get_default_context ());
661
657
662
658
if (error == OT_ERROR_NONE ) {
663
659
ot_msg_free (message_rep );
664
660
}
665
661
662
+ openthread_api_mutex_unlock (openthread_get_default_context ());
666
663
nrf_rpc_rsp_send_uint (group , error );
667
664
}
668
665
@@ -694,8 +691,12 @@ static void ot_rpc_cmd_coap_send_response(const struct nrf_rpc_group *group,
694
691
695
692
openthread_api_mutex_lock (openthread_get_default_context ());
696
693
error = otCoapSendResponse (openthread_get_default_instance (), message , & message_info );
697
- openthread_api_mutex_unlock (openthread_get_default_context ());
698
694
695
+ if (error == OT_ERROR_NONE ) {
696
+ ot_msg_free (message_rep );
697
+ }
698
+
699
+ openthread_api_mutex_unlock (openthread_get_default_context ());
699
700
nrf_rpc_rsp_send_uint (group , error );
700
701
}
701
702
0 commit comments