Commit a408f87
async_hooks: avoid decrementing iterator after erase
decrementing an iterator returned by `std::vector::erase` may have
undefined behaviour and should not be used. Decrementing `end()`
on an empty container is undefined and `.erase()` could leave
the container empty.
Instead, by calling `vec.erase(it--)` we decrement the valid iterator
before the erase operation but after being passed to the erase method.
In case of `AsyncHooks::RemoveContext` perform the cleanup of empty
contexts upfront using `std::remove_if` because the iteration gets
interrupted as soon as the context to be removed has been found.
PR-URL: #42749
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>1 parent 9cebb09 commit a408f87
1 file changed
+5
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
111 | | - | |
| 110 | + | |
112 | 111 | | |
113 | 112 | | |
114 | 113 | | |
| |||
251 | 250 | | |
252 | 251 | | |
253 | 252 | | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
254 | 257 | | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | 258 | | |
261 | 259 | | |
262 | 260 | | |
| |||
0 commit comments