Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbedConnectorInterface by
Diff: api/DynamicResource.cpp
- Revision:
- 22:192b598ba389
- Parent:
- 21:8487990a3baa
- Child:
- 23:caa0260acc21
--- a/api/DynamicResource.cpp Fri Mar 13 05:46:48 2015 +0000 +++ b/api/DynamicResource.cpp Fri Mar 13 06:22:41 2015 +0000 @@ -130,6 +130,7 @@ free(this->m_obs_token_ptr); this->m_obs_token_ptr = NULL; } + this->m_obs_token_ptr = (uint8_t*)malloc(received_coap_ptr->token_len); if(this->m_obs_token_ptr) { memcpy(this->m_obs_token_ptr, received_coap_ptr->token_ptr,received_coap_ptr->token_len); @@ -137,16 +138,25 @@ } } - if(received_coap_ptr->options_list_ptr->observe) { + // Observation handling... + if(received_coap_ptr->options_list_ptr && received_coap_ptr->options_list_ptr->observe) { coap_res_ptr->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); memset(coap_res_ptr->options_list_ptr, 0, sizeof(sn_coap_options_list_s)); - coap_res_ptr->options_list_ptr->observe_ptr = &this->m_obs_number; + coap_res_ptr->options_list_ptr->observe_ptr = &this->m_obs_number; // see nullify note below... coap_res_ptr->options_list_ptr->observe_len = 1; this->m_obs_number++; } // build out the response and send... sn_nsdl_send_coap_message(address,coap_res_ptr); + + // + // nullify note: + // + // because our obs_number (assigned to observe_ptr) is part of this object instance, we dont + // want to have the underlying free() try to free it... to just nullify here + // + if (coap_res_ptr->options_list_ptr) coap_res_ptr->options_list_ptr->observe_ptr = 0; } else { this->logger()->log("ERROR: resource(GET) mask is munged (mask: 0x%x)",this->m_res_mask); @@ -217,7 +227,7 @@ } sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr); - + return 0; }