We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1832

Summary: Memory leak issue in SDL_mixer-1.2.12/mixer.c file
Product: SDL_mixer Reporter: Nitz <nitin.j4>
Component: miscAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: 1.2.12   
Hardware: x86   
OS: Linux   

Description Nitz 2013-05-02 04:49:27 UTC
/* Load a wave file */
Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)
{

    // SOME CODE

    /* Allocate the chunk memory */
     chunk = (Mix_Chunk *)SDL_malloc(sizeof(Mix_Chunk));
     if ( chunk == NULL ) {
      SDL_SetError("Out of memory");
      if ( freesrc ) {
       SDL_RWclose(src);
      }
      return(NULL);
     }

     /* Find out what kind of audio file this is */
     magic = SDL_ReadLE32(src);
     /* Seek backwards for compatibility with older loaders */
     SDL_RWseek(src, -(int)sizeof(Uint32), RW_SEEK_CUR);

     switch (magic) {
      case WAVE:
      case RIFF:
       loaded = SDL_LoadWAV_RW(src, freesrc, &wavespec,
         (Uint8 **)&chunk->abuf, &chunk->alen);
       break;
      case FORM:
       loaded = Mix_LoadAIFF_RW(src, freesrc, &wavespec,
         (Uint8 **)&chunk->abuf, &chunk->alen);
       break;
    #ifdef OGG_MUSIC
      case OGGS:
       loaded = Mix_LoadOGG_RW(src, freesrc, &wavespec,
         (Uint8 **)&chunk->abuf, &chunk->alen);
       break;
    #endif
    #ifdef FLAC_MUSIC
      case FLAC:
       loaded = Mix_LoadFLAC_RW(src, freesrc, &wavespec,
         (Uint8 **)&chunk->abuf, &chunk->alen);
       break;
    #endif
      case CREA:
       loaded = Mix_LoadVOC_RW(src, freesrc, &wavespec,
         (Uint8 **)&chunk->abuf, &chunk->alen);
       break;
      default:
       SDL_SetError("Unrecognized sound file type");

       SDL_free(chunk);  // This line is added
       return(0);   
     }

    //SOME CODE

}

In this code chunk memory is dynamically allocated,
but in default case of switch(magic), it's getting leak.

So it is important to free this chunk memory. Patch is shown in the above code with a comment // This line is added.

Thanks and Regards,
Nitz
Comment 1 Sam Lantinga 2013-05-22 00:33:27 UTC
This is fixed for the next release, thanks!