[glib: 4/12] gdataset: Preserve destruction order




commit a4fa456e677246629e714d05b5de178691571b06
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Tue Jun 21 15:44:37 2022 -0400

    gdataset: Preserve destruction order
    
    In `g_data_remove_internal()`, call the `GDataElt:destroy` functions in the
    order that they appear in `keys`, instead of the order that they are found in
    `datalist`.
    
    Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/2672

 glib/gdataset.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/glib/gdataset.c b/glib/gdataset.c
index cc19c96749..2ac78b9d55 100644
--- a/glib/gdataset.c
+++ b/glib/gdataset.c
@@ -504,7 +504,7 @@ g_data_remove_internal (GData  **datalist,
       GDataElt *old, *data, *data_end;
       gsize found_keys;
 
-      old = g_newa (GDataElt, n_keys);
+      old = g_newa0 (GDataElt, n_keys);
 
       data = d->data;
       data_end = data + d->len;
@@ -518,6 +518,7 @@ g_data_remove_internal (GData  **datalist,
             {
               if (data->key == keys[i])
                 {
+                  old[i] = *data;
                   remove = TRUE;
                   break;
                 }
@@ -525,7 +526,6 @@ g_data_remove_internal (GData  **datalist,
 
           if (remove)
             {
-              old[found_keys] = *data;
               found_keys++;
 
               if (data < --data_end)
@@ -553,7 +553,7 @@ g_data_remove_internal (GData  **datalist,
         {
           g_datalist_unlock (datalist);
 
-          for (gsize i = 0; i < found_keys; i++)
+          for (gsize i = 0; i < n_keys; i++)
             {
               if (old[i].destroy)
                 old[i].destroy (old[i].data);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]