From 2676f23910c91ef0a02f28368171124c50132f49 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 27 Sep 2025 13:28:15 -0400 Subject: [PATCH] audio: fix crash in SDL_GetAudioStreamOutputChannelMap. Fixes #14058. --- src/audio/SDL_audio.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index ba6e2c21d2..54da689a92 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -171,10 +171,13 @@ int SDL_GetDefaultSampleFramesFromFreq(const int freq) int *SDL_ChannelMapDup(const int *origchmap, int channels) { - const size_t chmaplen = sizeof (*origchmap) * channels; - int *chmap = (int *)SDL_malloc(chmaplen); - if (chmap) { - SDL_memcpy(chmap, origchmap, chmaplen); + int *chmap = NULL; + if ((channels > 0) && origchmap) { + const size_t chmaplen = sizeof (*origchmap) * channels; + chmap = (int *)SDL_malloc(chmaplen); + if (chmap) { + SDL_memcpy(chmap, origchmap, chmaplen); + } } return chmap; } @@ -1617,9 +1620,7 @@ int *SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count) SDL_AudioDevice *device = ObtainPhysicalAudioDeviceDefaultAllowed(devid); if (device) { channels = device->spec.channels; - if (channels > 0 && device->chmap) { - result = SDL_ChannelMapDup(device->chmap, channels); - } + result = SDL_ChannelMapDup(device->chmap, channels); } ReleaseAudioDevice(device);