Revert "audio: plug leak and skip redundant copy in mixer add_stream"

This reverts commit 27ab9e722e.
This commit is contained in:
U-DESKTOP-SPFP6AQ\twistedtechre committed 2026-04-24 03:27:02 +02:00
1 parent 9faa65418d
commit 4be8b20911
4 files changed
+7 -45

No files matched your search

+7 -25
View File
@@ -1419,7 +1419,7 @@ bool audio_driver_mixer_add_stream(audio_mixer_stream_params_t *params)
void *buf = NULL;
if (params->stream_type == AUDIO_STREAM_TYPE_NONE)
goto error;
return false;
switch (params->slot_selection_type)
{
@@ -1436,27 +1436,17 @@ bool audio_driver_mixer_add_stream(audio_mixer_stream_params_t *params)
default:
if (!audio_driver_mixer_get_free_stream_slot(
&free_slot, params->stream_type))
goto error;
return false;
break;
}
if (params->state == AUDIO_STREAM_STATE_NONE)
goto error;
return false;
/* If the caller transferred buffer ownership, use it directly;
* otherwise make a private copy. The OGG/FLAC/MP3/MOD loaders
* retain the pointer for streaming decode, so taking ownership
* avoids a needless per-sound duplication and a matching leak
* (the original caller-owned buffer has nowhere to be freed,
* since the mixer frees only the internal copy). */
if (params->buf_owned)
buf = params->buf;
else
{
if (!(buf = malloc(params->bufsize)))
return false;
memcpy(buf, params->buf, params->bufsize);
}
if (!(buf = malloc(params->bufsize)))
return false;
memcpy(buf, params->buf, params->bufsize);
switch (params->type)
{
@@ -1531,14 +1521,6 @@ bool audio_driver_mixer_add_stream(audio_mixer_stream_params_t *params)
audio_driver_st.mixer_streams_playing++;
return true;
error:
/* On early failure (bad params / no slot), honor the ownership
* contract: if the caller transferred buf to us, we free it so
* the caller does not double-free and does not leak. */
if (params->buf_owned)
free(params->buf);
return false;
}
enum audio_mixer_state audio_driver_mixer_get_stream_state(unsigned i)
-8
View File
@@ -73,14 +73,6 @@ typedef struct audio_mixer_stream_params
enum audio_mixer_stream_type stream_type;
enum audio_mixer_type type;
enum audio_mixer_state state;
/* If true, add_stream takes ownership of buf and the caller must
* not free or otherwise reference it after the call returns. The
* buffer will be free()d either directly (WAV, once converted to
* PCM) or when the mixer sound is destroyed (OGG/FLAC/MP3/MOD,
* which retain the buffer for streaming decode).
* If false, add_stream copies buf internally and the caller retains
* ownership of the original memory. */
bool buf_owned;
} audio_mixer_stream_params_t;
#endif
-10
View File
@@ -116,7 +116,6 @@ static void task_audio_mixer_handle_upload_ogg(retro_task_t *task,
params.bufsize = img->bufsize;
params.cb = NULL;
params.basename = (img->path && *img->path) ? strdup(path_basename_nocompression(img->path)) : NULL;
params.buf_owned = true;
audio_driver_mixer_add_stream(&params);
@@ -148,7 +147,6 @@ static void task_audio_mixer_handle_upload_ogg_and_play(retro_task_t *task,
params.bufsize = img->bufsize;
params.cb = NULL;
params.basename = (img->path && *img->path) ? strdup(path_basename_nocompression(img->path)) : NULL;
params.buf_owned = true;
audio_driver_mixer_add_stream(&params);
@@ -180,7 +178,6 @@ static void task_audio_mixer_handle_upload_flac(retro_task_t *task,
params.bufsize = img->bufsize;
params.cb = NULL;
params.basename = (img->path && *img->path) ? strdup(path_basename_nocompression(img->path)) : NULL;
params.buf_owned = true;
audio_driver_mixer_add_stream(&params);
@@ -212,7 +209,6 @@ static void task_audio_mixer_handle_upload_flac_and_play(retro_task_t *task,
params.bufsize = img->bufsize;
params.cb = NULL;
params.basename = (img->path && *img->path) ? strdup(path_basename_nocompression(img->path)) : NULL;
params.buf_owned = true;
audio_driver_mixer_add_stream(&params);
@@ -244,7 +240,6 @@ static void task_audio_mixer_handle_upload_mp3(retro_task_t *task,
params.bufsize = img->bufsize;
params.cb = NULL;
params.basename = (img->path && *img->path) ? strdup(path_basename_nocompression(img->path)) : NULL;
params.buf_owned = true;
audio_driver_mixer_add_stream(&params);
@@ -276,7 +271,6 @@ static void task_audio_mixer_handle_upload_mp3_and_play(retro_task_t *task,
params.bufsize = img->bufsize;
params.cb = NULL;
params.basename = (img->path && *img->path) ? strdup(path_basename_nocompression(img->path)) : NULL;
params.buf_owned = true;
audio_driver_mixer_add_stream(&params);
@@ -308,7 +302,6 @@ static void task_audio_mixer_handle_upload_mod(retro_task_t *task,
params.bufsize = img->bufsize;
params.cb = NULL;
params.basename = (img->path && *img->path) ? strdup(path_basename_nocompression(img->path)) : NULL;
params.buf_owned = true;
audio_driver_mixer_add_stream(&params);
@@ -340,7 +333,6 @@ static void task_audio_mixer_handle_upload_mod_and_play(retro_task_t *task,
params.bufsize = img->bufsize;
params.cb = NULL;
params.basename = (img->path && *img->path) ? strdup(path_basename_nocompression(img->path)) : NULL;
params.buf_owned = true;
audio_driver_mixer_add_stream(&params);
@@ -373,7 +365,6 @@ static void task_audio_mixer_handle_upload_wav(retro_task_t *task,
params.bufsize = img->bufsize;
params.cb = NULL;
params.basename = (img->path && *img->path) ? strdup(path_basename_nocompression(img->path)) : NULL;
params.buf_owned = true;
audio_driver_mixer_add_stream(&params);
@@ -405,7 +396,6 @@ static void task_audio_mixer_handle_upload_wav_and_play(retro_task_t *task,
params.bufsize = img->bufsize;
params.cb = NULL;
params.basename = (img->path && *img->path) ? strdup(path_basename_nocompression(img->path)) : NULL;
params.buf_owned = true;
audio_driver_mixer_add_stream(&params);
-2
View File
@@ -558,8 +558,6 @@ static void handle_translation_response(
params.bufsize = response->sound_size;
params.cb = NULL;
params.basename = NULL;
/* Caller frees response->sound_data below; request a copy. */
params.buf_owned = false;
audio_driver_mixer_add_stream(&params);
}