[Answered] Releasing partition iterators ...

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

[Answered] Releasing partition iterators ...

Postby kolban » Fri Dec 02, 2016 3:50 am

When we call esp_partition_find() to get an iterator over the partition table, we are told to call esp_partition_iterator_release() to release it when done. That make sense. However, we also find that esp_partition_find() can return NULL. In this case, should we assume that there is nothing to be released and no need to call esp_partition_iterator_release()?

Next we look at esp_parition_next() which takes us to the next iterator. This function takes as input an iterator and returns an iterator. It also says that it can return NULL if there is no next entry. In this case ... I am confused on what to release in a variety of cases.

If I code:

Code: Select all

current_iterator = esp_partition_next(current_iterator);
Then the final value of current_iterator will be NULL ... I'm assuming that again there is nothing to release? It is starting to feel to like the only time we call esp_partition_iterator_release() is when:

a) We got an initial non NULL value
b) We have either not called esp_partition_next() or the last call to esp_parition_next() was not NULL
Last edited by kolban on Fri Dec 02, 2016 4:50 am, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Releasing partition iterators ...

Postby ESP_igrr » Fri Dec 02, 2016 3:56 am

It is okay to call esp_partition_release for a NULL iterator (just like it is okay to call free() for a null pointer). To simplify the code you can call release in all cases after the iteration loop, without checking for NULL.

Who is online

Users browsing this forum: No registered users and 100 guests