Memory Leak in IotMqtt_MallocMessage, pointers not freed after call to AwsIotShadow_TimedUpdate()

Hi,
We recently updated our codebase from a very early version of the AWS IoT library to the LTS version. As such, we are using the MQTT shim V2.3.1 and FreeRTOS Shadow V2.2.3.

It appears there is a memory leak inside AwsIotShadow_TimedUpdate() when calling

    /* Add a subscription to the Shadow "rejected" topic. */
    status = _modifyOperationSubscriptions( pOperation->mqttConnection,
                                            pTopicBuffer,
                                            topicFilterLength,
                                            callback,
                                            IotMqtt_TimedSubscribe );

and

       /* Add a subscription to the Shadow "accepted" topic. */
    status = _modifyOperationSubscriptions( pOperation->mqttConnection,
                                            pTopicBuffer,
                                            topicFilterLength,
                                            callback,
                                            IotMqtt_TimedSubscribe );

in aws_iot_shadow_subscription.c.

The memory allocated inside those functions, at

pTopicFilter = IotMqtt_MallocMessage( pSubscriptionList[ i ].topicFilterLength );

inside

IotMqttError_t _IotMqtt_AddSubscriptions()

never appears to be freed!

This was observed after some long term tests and we ran out of memory. I can tell the memory allocated here is not freed because I am saving the pointer it returns, and checking for it in the free(), and it never being provided.

Does this make sense?

Thanks

Hi @schoeler,

Thank you for bringing this to our attention. I am investigating this issue and will create a pull request to fix it.

Thank you

Hi @schoeler,

I have created a pull request to fix the memory leak. Thank you again for reporting this to us.

Hi Muneeb

Thanks for looking into this. I pulled it and it does fix the issue on our end too.

Thanks!

Ben