Simple Directmedia Layer

Don't free properties while modifying the property hashtable

A property cleanup callback might end up trying to set other properties, so we don't want to have a lock held at that point.

Fixes an assertion in testprocess when cleaning up IO stream properties

Changed files
+16 -5
src
+16 -5
src/SDL_properties.c
··· 81 81 SDL_FreePropertyWithCleanup(key, value, data, true); 82 82 } 83 83 84 - static void SDL_FreeProperties(const void *key, const void *value, void *data) 84 + static void SDL_FreeProperties(SDL_Properties *properties) 85 85 { 86 - SDL_Properties *properties = (SDL_Properties *)value; 87 86 if (properties) { 88 87 if (properties->props) { 89 88 SDL_DestroyHashTable(properties->props); ··· 103 102 return true; 104 103 } 105 104 106 - SDL_properties = SDL_CreateHashTable(NULL, 16, SDL_HashID, SDL_KeyMatchID, SDL_FreeProperties, true, false); 105 + SDL_properties = SDL_CreateHashTable(NULL, 16, SDL_HashID, SDL_KeyMatchID, NULL, true, false); 107 106 if (!SDL_properties) { 108 107 goto error; 109 108 } ··· 133 132 } 134 133 135 134 if (SDL_properties) { 135 + void *iter; 136 + const void *key, *value; 137 + 138 + iter = NULL; 139 + while (SDL_IterateHashTable(SDL_properties, &key, &value, &iter)) { 140 + SDL_FreeProperties((SDL_Properties *)value); 141 + } 136 142 SDL_DestroyHashTable(SDL_properties); 137 143 SDL_properties = NULL; 138 144 } ··· 200 206 } 201 207 202 208 error: 203 - SDL_FreeProperties(NULL, properties, NULL); 209 + SDL_FreeProperties(properties); 204 210 return 0; 205 211 } 206 212 ··· 790 796 791 797 void SDL_DestroyProperties(SDL_PropertiesID props) 792 798 { 799 + SDL_Properties *properties = NULL; 800 + 793 801 if (!props) { 794 802 return; 795 803 } 796 804 797 - SDL_RemoveFromHashTable(SDL_properties, (const void *)(uintptr_t)props); 805 + if (SDL_FindInHashTable(SDL_properties, (const void *)(uintptr_t)props, (const void **)&properties)) { 806 + SDL_FreeProperties(properties); 807 + SDL_RemoveFromHashTable(SDL_properties, (const void *)(uintptr_t)props); 808 + } 798 809 }