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

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