From c6127986bd7e4612c28bc1a2a1defee2e2e6ff67 Mon Sep 17 00:00:00 2001
From: Petar Popovic <[EMAIL REDACTED]>
Date: Sun, 27 Jul 2025 12:14:15 +0200
Subject: [PATCH] Freeing memory on error
---
src/decoder_opus.c | 2 ++
src/decoder_stb_vorbis.c | 1 +
src/decoder_vorbis.c | 2 ++
3 files changed, 5 insertions(+)
diff --git a/src/decoder_opus.c b/src/decoder_opus.c
index f85be7c0..956965ae 100644
--- a/src/decoder_opus.c
+++ b/src/decoder_opus.c
@@ -151,12 +151,14 @@ static bool SDLCALL OPUS_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec, SDL_P
// now open the stream for serious processing.
of = opus.op_open_callbacks(io, &OPUS_IoCallbacks, NULL, 0, &rc);
if (!of) {
+ SDL_free(adata);
return set_op_error("ov_open_callbacks", rc);
}
const OpusHead *info = opus.op_head(of, -1);
if (!info) {
opus.op_free(of);
+ SDL_free(adata);
return SDL_SetError("Couldn't get Opus info; corrupt data?");
}
diff --git a/src/decoder_stb_vorbis.c b/src/decoder_stb_vorbis.c
index 8e1be98b..ad04c48f 100644
--- a/src/decoder_stb_vorbis.c
+++ b/src/decoder_stb_vorbis.c
@@ -157,6 +157,7 @@ static bool SDLCALL STBVORBIS_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec,
int error = 0;
stb_vorbis *vorbis = stb_vorbis_open_io(io, 0, &error, NULL);
if (!vorbis) {
+ SDL_free(adata);
return SetStbVorbisError("stb_vorbis_open_memory", error);
}
diff --git a/src/decoder_vorbis.c b/src/decoder_vorbis.c
index dc2af7a7..4cb26438 100644
--- a/src/decoder_vorbis.c
+++ b/src/decoder_vorbis.c
@@ -171,12 +171,14 @@ static bool SDLCALL VORBIS_init_audio(SDL_IOStream *io, SDL_AudioSpec *spec, SDL
// now open the stream for serious processing.
const int rc = vorbis.ov_open_callbacks(io, &vf, NULL, 0, VORBIS_IoCallbacks);
if (rc < 0) {
+ SDL_free(adata);
return SetOggVorbisError("ov_open_callbacks", rc);
}
const vorbis_info *vi = vorbis.ov_info(&vf, -1);
if (!vi) {
vorbis.ov_clear(&vf);
+ SDL_free(adata);
return SDL_SetError("Couldn't get Ogg Vorbis info; corrupt data?");
}