Repository: libsdl-org/SDL
File: src/audio/SDL_audio.c (C)

Code before:
{
    // bit #1 of devid is set for physical devices and unset for logical.
    const SDL_AudioDeviceID devid = (SDL_AudioDeviceID) (uintptr_t) key;
    const bool isphysical = !!(devid & (1<<1));
    if (isphysical) {
        SDL_AudioDevice *dev = (SDL_AudioDevice *) value;

        SDL_assert(dev->instance_id == devid);
        DestroyPhysicalAudioDevice(dev);
    }
    return true;  // keep iterating.
}

void SDL_QuitAudio(void)
{
    if (!current_audio.name) {  // not initialized?!
        return;
    }

    current_audio.impl.DeinitializeStart();

    // Destroy any audio streams that still exist...unless app asked to keep it.
    SDL_AudioStream *next = NULL;
    for (SDL_AudioStream *i = current_audio.existing_streams; i; i = next) {
        next = i->next;
        if (i->simplified || !SDL_GetBooleanProperty(i->props, SDL_PROP_AUDIOSTREAM_KEEP_ON_SHUTDOWN_BOOLEAN, false)) {
            SDL_DestroyAudioStream(i);
        }
    }

    SDL_LockRWLockForWriting(current_audio.device_hash_lock);
    SDL_SetAtomicInt(&current_audio.shutting_down, 1);
    SDL_HashTable *device_hash = current_audio.device_hash;
    current_audio.device_hash = NULL;
    SDL_PendingAudioDeviceEvent *pending_events = current_audio.pending_events.next;
    current_audio.pending_events.next = NULL;
    SDL_SetAtomicInt(&current_audio.playback_device_count, 0);
    SDL_SetAtomicInt(&current_audio.recording_device_count, 0);
    SDL_UnlockRWLock(current_audio.device_hash_lock);

    SDL_PendingAudioDeviceEvent *pending_next = NULL;
    for (SDL_PendingAudioDeviceEvent *i = pending_events; i; i = pending_next) {
        pending_next = i->next;
        SDL_free(i);
    }

    SDL_IterateHashTable(device_hash, DestroyOnePhysicalAudioDevice, NULL);

    // Free the driver data
    current_audio.impl.Deinitialize();


Review comment (suggestion):
```suggestion
        } else {
            i->prev = NULL;
            i->next = NULL;
        }
```

Code after:
        SDL_AudioDevice *dev = (SDL_AudioDevice *) value;

        SDL_assert(dev->instance_id == devid);
        DestroyPhysicalAudioDevice(dev);
    }
    return true;  // keep iterating.
}

void SDL_QuitAudio(void)
{
    if (!current_audio.name) {  // not initialized?!
        return;
    }

    current_audio.impl.DeinitializeStart();

    // Destroy any audio streams that still exist...unless app asked to keep it.
    SDL_AudioStream *next = NULL;
    for (SDL_AudioStream *i = current_audio.existing_streams; i; i = next) {
        next = i->next;
        if (i->simplified || !SDL_GetBooleanProperty(i->props, SDL_PROP_AUDIOSTREAM_KEEP_ON_SHUTDOWN_BOOLEAN, false)) {
            SDL_DestroyAudioStream(i);
        } else {
            i->prev = NULL;
            i->next = NULL;
        }
    }

    SDL_LockRWLockForWriting(current_audio.device_hash_lock);
    SDL_SetAtomicInt(&current_audio.shutting_down, 1);
    SDL_HashTable *device_hash = current_audio.device_hash;
    current_audio.device_hash = NULL;
    SDL_PendingAudioDeviceEvent *pending_events = current_audio.pending_events.next;
    current_audio.pending_events.next = NULL;
    SDL_SetAtomicInt(&current_audio.playback_device_count, 0);
    SDL_SetAtomicInt(&current_audio.recording_device_count, 0);
    SDL_UnlockRWLock(current_audio.device_hash_lock);

    SDL_PendingAudioDeviceEvent *pending_next = NULL;
    for (SDL_PendingAudioDeviceEvent *i = pending_events; i; i = pending_next) {
        pending_next = i->next;
        SDL_free(i);
    }

    SDL_IterateHashTable(device_hash, DestroyOnePhysicalAudioDevice, NULL);

    // Free the driver data
    current_audio.impl.Deinitialize();

    SDL_DestroyRWLock(current_audio.device_hash_lock);
    SDL_DestroyHashTable(device_hash);