Fix memory leak on realloc failure in digi_mixer_music

This commit is contained in:
Kp 2012-11-24 16:26:53 +00:00
parent caaf44e358
commit 7a85d4af05
2 changed files with 16 additions and 6 deletions

View file

@ -87,11 +87,16 @@ int mix_play_file(char *filename, int loop, void (*hook_finished_track)())
filehandle = PHYSFS_openRead(filename);
if (filehandle != NULL)
{
current_music_hndlbuf = d_realloc(current_music_hndlbuf, sizeof(char *)*PHYSFS_fileLength(filehandle));
bufsize = PHYSFS_read(filehandle, current_music_hndlbuf, sizeof(char), PHYSFS_fileLength(filehandle));
unsigned len = PHYSFS_fileLength(filehandle);
unsigned char *p = (unsigned char *)d_realloc(current_music_hndlbuf, sizeof(char)*len);
if (p)
{
current_music_hndlbuf = p;
bufsize = PHYSFS_read(filehandle, current_music_hndlbuf, sizeof(char), len);
rw = SDL_RWFromConstMem(current_music_hndlbuf,bufsize*sizeof(char));
PHYSFS_close(filehandle);
current_music = Mix_LoadMUS_RW(rw);
}
PHYSFS_close(filehandle);
}
}

View file

@ -87,11 +87,16 @@ int mix_play_file(char *filename, int loop, void (*hook_finished_track)())
filehandle = PHYSFS_openRead(filename);
if (filehandle != NULL)
{
current_music_hndlbuf = d_realloc(current_music_hndlbuf, sizeof(char *)*PHYSFS_fileLength(filehandle));
bufsize = PHYSFS_read(filehandle, current_music_hndlbuf, sizeof(char), PHYSFS_fileLength(filehandle));
unsigned len = PHYSFS_fileLength(filehandle);
unsigned char *p = (unsigned char *)d_realloc(current_music_hndlbuf, sizeof(char)*len);
if (p)
{
current_music_hndlbuf = p;
bufsize = PHYSFS_read(filehandle, current_music_hndlbuf, sizeof(char), len);
rw = SDL_RWFromConstMem(current_music_hndlbuf,bufsize*sizeof(char));
PHYSFS_close(filehandle);
current_music = Mix_LoadMUS_RW(rw);
}
PHYSFS_close(filehandle);
}
}