Proper AWS sequence on intermittent WiFi connection + possible memory leak(s)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
EyLa_3227556
Level 3
Level 3
10 replies posted 5 replies posted 10 questions asked

Hello,

My app connects to AWS over WiFi intermittently.

Please advise if the following sequence is correct-

  1. wiced_network_up()
  2. wiced_aws_init()
  3. wiced_aws_create_endpoint()
  4. wiced_aws_connect()
  5. bunch of wiced_aws_subscribe()
  6. bunch of wiced_aws_publish()
  7. wiced_aws_disconnect()
  8. wiced_aws_deinit()
  9. wicefd_network_down()
  10. After X minutes goto 1

Is it possible to shorten reconnection time described above by calling wiced_aws_init()/wiced_aws_create_endpoint() once upon the first connection, or does it have to be called on every (re)connection

Also,

There seem to be a memory leak when calling wiced_aws_disconnect().

At the end of the function there's a call to "free(aws)".

However the parameter  aws that was dynamically allocated in wiced_aws_create_endpoint(), has an internal dynamic allocation (aws->mqtt.base) taking place in aws_internal_mqtt_init() that is not freed when its parent object (aws) is being freed !

Also(2),

Was this reported memory leak handled in the latest SDK? Should I follow the suggested solution in the post?

Your guidelines on how to deal with this use case are highly valuable and appreciated

Thanks

0 Likes
3 Replies
RaktimR_11
Moderator
Moderator
Moderator
500 replies posted 250 replies posted 100 replies posted

You can use the solution suggested in the mentioned thread. After that thread, there hasn't been a wiced release; so, you would need to fix it in your local setup for now.

If you are putting the device to sleep by suspending network activity, then you have to follow the sequence quoted above

wiced applications are a means to get you started; like the default publisher in 43xxx_Wi-Fi/apps/demo/aws/iot/pub_sub/publisher/publisher.c doesn't handle the disconnection events at all. They are by no means perfect and hence, I would recommend you to check the memory leak in case of your connection teardown and free the base object correctly.

0 Likes

Hi,

Thanks for your prompt reply.

I understand that the wiced samples are, well, samples... and are not fully fledged apps.

I was referring to a memory leak in the underlying SDK in the file libraries/protocols/AWS/wiced_aws.c

2020-09-09 23_39_49-C_C++ - 43xxx_Wi-Fi_libraries_protocols_AWS_wiced_aws.c - Eclipse.png

0 Likes

Thanks for the beautiful explanation . What I meant earlier is that since in the default snippet, we are not handling the disconnection at all; it might have gone completely unnoticed from our side. Fair warning: there might be other memory leaks as well. I will request you to do a mallinfo in your application for finding out other such bugs.

Meanwhile, you can add line #398 in 43xxx_Wi-Fi/libraries/protocols/AWS/wiced_aws.c free(aws->mqtt.base).

pastedImage_1.png

Additionally, in line #290 in 43xxx_Wi-Fi/libraries/protocols/AWS/aws_mqtt.c, you can add the following three lines from wiced_mqtt_deinit

pastedImage_0.png

I will update the thread as and when I find any other issue.

0 Likes