diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-07-22 15:13:57 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-08-23 09:55:32 -0700 |
commit | 5511e9a4e85c8eb8a67a8cfc56a2b1f665a8940d (patch) | |
tree | b1bafbb7c2687f6350e9f5aba080e81cb70f8803 /test/src | |
parent | 6bbb2e4c2b5fdb07be229b3eee03f355dc3103e5 (diff) | |
download | qtlocation-mapboxgl-5511e9a4e85c8eb8a67a8cfc56a2b1f665a8940d.tar.gz |
[tests] Fix a subtle ordering bug in StubFileSource
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/mbgl/test/stub_file_source.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/test/src/mbgl/test/stub_file_source.cpp b/test/src/mbgl/test/stub_file_source.cpp index 75d7e2d072..ec0545e88c 100644 --- a/test/src/mbgl/test/stub_file_source.cpp +++ b/test/src/mbgl/test/stub_file_source.cpp @@ -24,11 +24,19 @@ StubFileSource::StubFileSource() { for (auto& pair : pending_) { optional<Response> res = std::get<1>(pair.second)(std::get<0>(pair.second)); if (res) { - std::get<2>(pair.second)(*res); - + // This must be before calling the callback, because it's possible that the callback + // could: + // + // 1. Deallocate the AsyncRequest itself, thus removing it from pending + // 2. Allocate a new AsyncRequest at the same memory location + // + // If remove(pair.first) was called after both those things happened, it would + // remove the newly allocated request rather than the intended request. if (!res->error) { remove(pair.first); } + + std::get<2>(pair.second)(*res); } } }); |