main-grpc: Fix iterator going invalid at destruction time 95/29695/2
authorMarius Vlad <marius.vlad@collabora.com>
Wed, 21 Feb 2024 08:44:54 +0000 (10:44 +0200)
committerMarius Vlad <marius.vlad@collabora.com>
Fri, 23 Feb 2024 16:08:16 +0000 (18:08 +0200)
Apparently, erase() would make the iterator invalid so we need grab
the next one to have the work correctly.

Bug-AGL: SPEC-5077
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Change-Id: I290fa1231eb6b37ab63c5f5c0bd8fe90d4363a77

grpc-proxy/main-grpc.cpp

index 92d4862..db33032 100644 (file)
@@ -272,9 +272,8 @@ global_remove(void *data, struct wl_registry *reg, uint32_t id)
        (void) id;
 
        for (std::list<global_data>::iterator it = sh->globals.begin();
-                       it != sh->globals.end(); it++) {
-               sh->globals.erase(it);
-       }
+                       it != sh->globals.end(); it = sh->globals.erase(it))
+               ;
 }
 
 static const struct wl_registry_listener registry_listener = {
@@ -395,9 +394,8 @@ destroy_shell_data(struct shell_data *sh)
                 destroy_output(w_output);
 
        for (std::list<global_data>::iterator it = sh->globals.begin();
-                      it != sh->globals.end(); it++) {
-              sh->globals.erase(it);
-       }
+                      it != sh->globals.end(); it = sh->globals.erase(it))
+              ;
 
         wl_display_flush(sh->wl_display);
         wl_display_disconnect(sh->wl_display);