Skip to content

Commit

Permalink
Fix a possible double file close when decoder initialization fails.
Browse files Browse the repository at this point in the history
Public issue #319
  • Loading branch information
mackron committed Jun 11, 2021
1 parent a10e763 commit 8234df8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion miniaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -48127,7 +48127,10 @@ MA_API ma_result ma_decoder_init_vfs(ma_vfs* pVFS, const char* pFilePath, const
}

if (result != MA_SUCCESS) {
ma_vfs_or_default_close(pVFS, pDecoder->backend.vfs.file);
if (pDecoder->backend.vfs.file != NULL) { /* <-- Will be reset to NULL if ma_decoder_uninit() is called in one of the steps above which allows us to avoid a double close of the file. */
ma_vfs_or_default_close(pVFS, pDecoder->backend.vfs.file);
}

return result;
}

Expand Down Expand Up @@ -48528,6 +48531,7 @@ MA_API ma_result ma_decoder_uninit(ma_decoder* pDecoder)

if (pDecoder->onRead == ma_decoder__on_read_vfs) {
ma_vfs_or_default_close(pDecoder->backend.vfs.pVFS, pDecoder->backend.vfs.file);
pDecoder->backend.vfs.file = NULL;
}

ma_data_converter_uninit(&pDecoder->converter);
Expand Down

0 comments on commit 8234df8

Please # to comment.