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 - Memory leak issue in SDL_mixer-1.2.12/music.c file
Summary: Memory leak issue in SDL_mixer-1.2.12/music.c file
Status: RESOLVED FIXED
Alias: None
Product: SDL_mixer
Classification: Unclassified
Component: misc (show other bugs)
Version: 1.2.12
Hardware: x86 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-02 04:56 UTC by Nitz
Modified: 2013-05-22 00:32 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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!