From: Changgyu Choi Date: Mon, 21 Nov 2022 01:14:40 +0000 (+0900) Subject: Fix wrong bundle_foreach implementation X-Git-Tag: accepted/tizen/7.0/unified/20221122.014846~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=31d85a4f267263044c57ee29db04d511ccee2df1;p=platform%2Fcore%2Fbase%2Fbundle.git Fix wrong bundle_foreach implementation if data is removed through bundle_foreach(), A crash may occur. This patch resolves this by passing the iterator to the next before calling the callback using the iterator. Change-Id: I3f04418f47bc17247e857362b462e616c2136fa0 Signed-off-by: Changgyu Choi --- diff --git a/src/stub.cc b/src/stub.cc index fdfc9dc..540ca4c 100644 --- a/src/stub.cc +++ b/src/stub.cc @@ -160,10 +160,12 @@ extern "C" EXPORT_API void bundle_foreach(bundle* b, } auto* h = reinterpret_cast(b); - for (const auto& kv : h->GetMap()) { - auto& key_info = kv.second; + auto it = h->GetMap().begin(); + while (it != h->GetMap().end()) { + auto& key_info = it->second; + ++it; callback(key_info->GetKey().c_str(), key_info->GetType(), - reinterpret_cast(key_info.get()), user_data); + reinterpret_cast(key_info.get()), user_data); } set_last_result(BUNDLE_ERROR_NONE);