| Summary: | Mix_LoadWAV_RW cannot load the OGG file. | ||
|---|---|---|---|
| Product: | SDL_mixer | Reporter: | aki. <c> |
| Component: | misc | Assignee: | Ryan C. Gordon <icculus> |
| Status: | VERIFIED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | gcarlton |
| Version: | unspecified | ||
| Hardware: | x86 | ||
| OS: | Other | ||
| Attachments: | Fix audio buffer being freed in the wrong library. | ||
|
Description
aki.
2006-12-01 23:35:34 UTC
Fixed in svn, revision 2929 Confirmed it. Thanks for your work. *** Bug 307 has been marked as a duplicate of this bug. *** Created attachment 523 [details]
Fix audio buffer being freed in the wrong library.
Sorry to hijack this bug, but I believe it may not be fixed from the problems I'm getting, which seems identical to the symptoms here. I wasn't sure whether to hijack this or file a new bug, as the bug is slightly larger in scope than what is reported here. Here is probably the best place.
The issue seems to be that the audio buffer is being freed in the wrong library. When sounds are played in the WAV or RIFF format, SDL_LoadWAV_RW() is called which is part of the SDL shared library, and the audio buffer is allocated there. Calling SDL_FreeWAV() then frees the buffer in that library. However, when other formats are played such as OGG, the audio buffer is allocated in the SDL_mixer library instead, and SDL_FreeWAV() is still called. This attempts to free the buffer in the wrong library as it is not allocated there. It can result in memory corruption and a possible memory leak as the audio buffer in the SDL_mixer library is not freed.
The bug is slightly larger in scope because a similar thing happens in Mix_FreeChunk(). This time, free() is used to free the audio buffer, which frees it in the SDL_mixer library. However, it also means if the WAV or RIFF format is used for the chunk, the audio buffer is freed in the wrong library and could result in memory corruption and a memory leak.
The fix for this would be to call the correct free function depending on which library the audio buffer was allocated. This seems to fix the crashes I've been getting.
This patch is what I've done to my working copy. It should work for both 1.2.11 and the latest hg revision as the line numbers are identical. It adds a new internal function which acts as a wrapper to call the correct free function for the audio buffer. The Mix_Chunk struct was also modified to store whether or not the audio buffer is allocated in the SDL shared library or not. It's an API change but one which should retain backwards compatibility with all software that uses SDL_mixer. Hopefully, that's classed as acceptable. :)
|