dynamic_modplug.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 17 Jun 2015 00:11:41 -0700
changeset 705 fe757163b8f7
parent 642 dae7bb0a66b1
child 711 f40c5ac95b12
permissions -rw-r--r--
Fixed bug 3018 - Loading MIDI music using FluidSynth leaks memory.

Philipp Wiesemann

There is a memory leak in fluidsynth.c and fluidsynth_loadsong_RW_internal(). The allocated temporary buffer is not deleted if fluid_player_add_mem() returns FLUID_OK.
     1 /*
     2   SDL_mixer:  An audio mixer library based on the SDL library
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 #ifdef MODPLUG_MUSIC
    23 
    24 #include "SDL_loadso.h"
    25 #include "SDL_mixer.h"
    26 #include "dynamic_modplug.h"
    27 
    28 modplug_loader modplug = {
    29     0, NULL
    30 };
    31 
    32 #ifdef MODPLUG_DYNAMIC
    33 int Mix_InitModPlug()
    34 {
    35     if ( modplug.loaded == 0 ) {
    36         modplug.handle = SDL_LoadObject(MODPLUG_DYNAMIC);
    37         if ( modplug.handle == NULL ) {
    38             return -1;
    39         }
    40 
    41         modplug.ModPlug_Load =
    42             (ModPlugFile* (*)(const void* data, int size))
    43             SDL_LoadFunction(modplug.handle, "ModPlug_Load");
    44 
    45         modplug.ModPlug_Unload =
    46             (void (*)(ModPlugFile* file))
    47             SDL_LoadFunction(modplug.handle, "ModPlug_Unload");
    48 
    49         modplug.ModPlug_Read =
    50             (int  (*)(ModPlugFile* file, void* buffer, int size))
    51             SDL_LoadFunction(modplug.handle, "ModPlug_Read");
    52 
    53         modplug.ModPlug_Seek =
    54             (void (*)(ModPlugFile* file, int millisecond))
    55             SDL_LoadFunction(modplug.handle, "ModPlug_Seek");
    56 
    57         modplug.ModPlug_GetSettings =
    58             (void (*)(ModPlug_Settings* settings))
    59             SDL_LoadFunction(modplug.handle, "ModPlug_GetSettings");
    60 
    61         modplug.ModPlug_SetSettings =
    62             (void (*)(const ModPlug_Settings* settings))
    63             SDL_LoadFunction(modplug.handle, "ModPlug_SetSettings");
    64 
    65         modplug.ModPlug_SetMasterVolume =
    66             (void (*)(ModPlugFile* file,unsigned int cvol))
    67             SDL_LoadFunction(modplug.handle, "ModPlug_SetMasterVolume");
    68     }
    69     ++modplug.loaded;
    70 
    71     return 0;
    72 }
    73 
    74 void Mix_QuitModPlug()
    75 {
    76     if ( modplug.loaded == 0 ) {
    77         return;
    78     }
    79     if ( modplug.loaded == 1 ) {
    80         SDL_UnloadObject(modplug.handle);
    81     }
    82     --modplug.loaded;
    83 }
    84 #else
    85 int Mix_InitModPlug()
    86 {
    87     if ( modplug.loaded == 0 ) {
    88 #ifdef __MACOSX__
    89         extern ModPlugFile* ModPlug_Load(const void* data, int size) __attribute__((weak_import));
    90         if ( ModPlug_Load == NULL )
    91         {
    92             /* Missing weakly linked framework */
    93             Mix_SetError("Missing modplug.framework");
    94             return -1;
    95         }
    96 #endif // __MACOSX__
    97 
    98         modplug.ModPlug_Load = ModPlug_Load;
    99         modplug.ModPlug_Unload = ModPlug_Unload;
   100         modplug.ModPlug_Read = ModPlug_Read;
   101         modplug.ModPlug_Seek = ModPlug_Seek;
   102         modplug.ModPlug_GetSettings = ModPlug_GetSettings;
   103         modplug.ModPlug_SetSettings = ModPlug_SetSettings;
   104         modplug.ModPlug_SetMasterVolume = ModPlug_SetMasterVolume;
   105     }
   106     ++modplug.loaded;
   107 
   108     return 0;
   109 }
   110 void Mix_QuitModPlug()
   111 {
   112     if ( modplug.loaded == 0 ) {
   113         return;
   114     }
   115     if ( modplug.loaded == 1 ) {
   116     }
   117     --modplug.loaded;
   118 }
   119 #endif /* MODPLUG_DYNAMIC */
   120 
   121 #endif /* MODPLUG_MUSIC */