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 1833

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

Description Nitz 2013-05-02 04:56:52 UTC
Mix_Music *Mix_LoadMUSType_RW(SDL_RWops *rw, Mix_MusicType type, int freesrc)

{

    // SOME CODE

     /* Allocate memory for the music structure */
     music = (Mix_Music *)SDL_malloc(sizeof(Mix_Music));
     if (music == NULL ) {
      Mix_SetError("Out of memory");
      return NULL;
     }
     music->error = 0;

     switch (type) {
     #ifdef WAV_MUSIC
     case MUS_WAV:
      /* The WAVE loader needs the first 4 bytes of the header */
      {
       Uint8 magic[5];
       int start = SDL_RWtell(rw);
       if (SDL_RWread(rw, magic, 1, 4) != 4) {
        Mix_SetError("Couldn't read from RWops");

        SDL_free(music); // This line is added
        return MUS_NONE;
       }

    // SOME CODE

  }

In this code 'music' is dynamically allocated. But memory get leaked at return MUS_NONE.

So it is important to free the 'music'. Patch is added in the above code with the comment // This line is added.

Thanks & Regards,
Nitz
Comment 1 Sam Lantinga 2013-05-22 00:32:01 UTC
Fixed, thanks!