You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code in file iothub_client_sample_mqtt.c will lead to a crash:
static void SendConfirmationCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback)
{
EVENT_INSTANCE* eventInstance = (EVENT_INSTANCE*)userContextCallback;
size_t id = eventInstance->messageTrackingId;
if (result == IOTHUB_CLIENT_CONFIRMATION_OK) {
(void)printf("Confirmation[%d] received for message tracking id = %d with result = %s\r\n", callbackCounter, (int)id, MU_ENUM_TO_STRING(IOTHUB_CLIENT_CONFIRMATION_RESULT, result));
/* Some device specific action code goes here... */
callbackCounter++;
}
IoTHubMessage_Destroy(eventInstance->messageHandle);
}
The problem is the IoTHubMessage_Destroy call in the end when the function is called with result IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY . The callback is going to destroy the message also, leading to corrupted memory...
The correct code:
static void SendConfirmationCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback)
{
EVENT_INSTANCE* eventInstance = (EVENT_INSTANCE*)userContextCallback;
size_t id = eventInstance->messageTrackingId;
if (result == IOTHUB_CLIENT_CONFIRMATION_OK) {
(void)printf("Confirmation[%d] received for message tracking id = %d with result = %s\r\n", callbackCounter, (int)id, MU_ENUM_TO_STRING(IOTHUB_CLIENT_CONFIRMATION_RESULT, result));
/* Some device specific action code goes here... */
callbackCounter++;
}
if (result != IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY)
IoTHubMessage_Destroy(eventInstance->messageHandle);
}
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
iothub_client_sample_mqtt iothubmessage_destroy crash
iothub_client_sample_mqtt iothubmessage_destroy crash (CA-251)
Oct 31, 2022
Lisa999
changed the title
iothub_client_sample_mqtt iothubmessage_destroy crash (CA-251)
Example iothub_client_sample_mqtt iothubmessage_destroy crash (CA-251)
Oct 31, 2022
Lisa999
changed the title
Example iothub_client_sample_mqtt iothubmessage_destroy crash (CA-251)
Example iothub_client_sample_mqtt crash (CA-251)
Oct 31, 2022
This code in file iothub_client_sample_mqtt.c will lead to a crash:
The problem is the IoTHubMessage_Destroy call in the end when the function is called with result IOTHUB_CLIENT_CONFIRMATION_BECAUSE_DESTROY . The callback is going to destroy the message also, leading to corrupted memory...
The correct code:
The text was updated successfully, but these errors were encountered: