From 9f4460797f6a7b0b12de09b20b42145df2708424 Mon Sep 17 00:00:00 2001 From: David Reid Date: Thu, 1 Jul 2021 14:36:22 +1000 Subject: [PATCH] Fix memory leaks. --- examples/custom_decoder.c | 4 ++++ research/_examples/custom_decoder_engine.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/examples/custom_decoder.c b/examples/custom_decoder.c index eaf13b71..61d35dd2 100644 --- a/examples/custom_decoder.c +++ b/examples/custom_decoder.c @@ -38,6 +38,7 @@ static ma_result ma_decoding_backend_init__libvorbis(void* pUserData, ma_read_pr result = ma_libvorbis_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pVorbis); if (result != MA_SUCCESS) { + ma_free(pVorbis, pAllocationCallbacks); return result; } @@ -60,6 +61,7 @@ static ma_result ma_decoding_backend_init_file__libvorbis(void* pUserData, const result = ma_libvorbis_init_file(pFilePath, pConfig, pAllocationCallbacks, pVorbis); if (result != MA_SUCCESS) { + ma_free(pVorbis, pAllocationCallbacks); return result; } @@ -113,6 +115,7 @@ static ma_result ma_decoding_backend_init__libopus(void* pUserData, ma_read_proc result = ma_libopus_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pOpus); if (result != MA_SUCCESS) { + ma_free(pOpus, pAllocationCallbacks); return result; } @@ -135,6 +138,7 @@ static ma_result ma_decoding_backend_init_file__libopus(void* pUserData, const c result = ma_libopus_init_file(pFilePath, pConfig, pAllocationCallbacks, pOpus); if (result != MA_SUCCESS) { + ma_free(pOpus, pAllocationCallbacks); return result; } diff --git a/research/_examples/custom_decoder_engine.c b/research/_examples/custom_decoder_engine.c index 709ae41d..1b39ff16 100644 --- a/research/_examples/custom_decoder_engine.c +++ b/research/_examples/custom_decoder_engine.c @@ -39,6 +39,7 @@ static ma_result ma_decoding_backend_init__libvorbis(void* pUserData, ma_read_pr result = ma_libvorbis_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pVorbis); if (result != MA_SUCCESS) { + ma_free(pVorbis, pAllocationCallbacks); return result; } @@ -61,6 +62,7 @@ static ma_result ma_decoding_backend_init_file__libvorbis(void* pUserData, const result = ma_libvorbis_init_file(pFilePath, pConfig, pAllocationCallbacks, pVorbis); if (result != MA_SUCCESS) { + ma_free(pVorbis, pAllocationCallbacks); return result; } @@ -114,6 +116,7 @@ static ma_result ma_decoding_backend_init__libopus(void* pUserData, ma_read_proc result = ma_libopus_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pOpus); if (result != MA_SUCCESS) { + ma_free(pOpus, pAllocationCallbacks); return result; } @@ -136,6 +139,7 @@ static ma_result ma_decoding_backend_init_file__libopus(void* pUserData, const c result = ma_libopus_init_file(pFilePath, pConfig, pAllocationCallbacks, pOpus); if (result != MA_SUCCESS) { + ma_free(pOpus, pAllocationCallbacks); return result; }