aws / aws-iot-device-sdk-embedded-C

SDK for connecting to AWS IoT from a device using embedded C.
MIT License
974 stars 622 forks source link

OTA_Shutdown() not releasing resources #1910

Open coratron opened 1 month ago

coratron commented 1 month ago

I am using the following:

The problem:

The OTA task consumes about 10kB of RAM. Calling OTA_Shutdown() should release the resources but it is not.

Confirmed with logs by checking the RAM before and after, as well as verbose logging which ends in I (100117) AWS_OTA: OTA Agent stopped.

I am basing my code on the OTA example. In other words, the result should be reproducible by measuring the RAM watermark before aws_iot_ota() and at the end of it.

coratron commented 1 month ago

Leaving this here until someone has a look:

I have solved the issue and recommend modifying the otaThread function in the example to:

void* otaThread(void* pParam)
{
    /* Calling OTA agent task. */
    OTA_EventProcessingTask(pParam);
    LogInfo(("OTA Agent stopped."));

    pthread_detach(pthread_self());
    pthread_exit(NULL);

    return NULL;
}

Otherwise the resources allocated to the thread will not be released.

coratron commented 1 month ago

Restarting OTA is the next issue after releasing the resources : the system gets caught here on the second start up pass:

  else
        {
            /* Drop all events that created after OTA_Shutdown. */
            resetEventQueue();
        }

in OTA_Init

paulbartell commented 1 month ago

@coratron Thanks for the bug report. Would you mind opening a Pull Request with your suggested fix?