On shutdown, deallocate global memory we might have allocated for effects.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 15 Jul 2007 15:43:02 +0000
changeset 35983eaf245b7e7
parent 358 5f35def7a29a
child 360 61cddad42a8a
On shutdown, deallocate global memory we might have allocated for effects.

Partially fixes Bugzilla #385.
effect_position.c
effects_internal.c
effects_internal.h
mixer.c
     1.1 --- a/effect_position.c	Sun Jul 15 10:24:36 2007 +0000
     1.2 +++ b/effect_position.c	Sun Jul 15 15:43:02 2007 +0000
     1.3 @@ -79,6 +79,20 @@
     1.4  static position_args *pos_args_global = NULL;
     1.5  static int position_channels = 0;
     1.6  
     1.7 +void _Eff_PositionDeinit(void)
     1.8 +{
     1.9 +    int i;
    1.10 +    for (i = 0; i < position_channels; i++) {
    1.11 +        free(pos_args_array[i]);
    1.12 +    }
    1.13 +
    1.14 +    free(pos_args_global);
    1.15 +    pos_args_global = NULL;
    1.16 +    free(pos_args_array);
    1.17 +    pos_args_array = NULL;
    1.18 +}
    1.19 +
    1.20 +
    1.21  /* This just frees up the callback-specific data. */
    1.22  static void _Eff_PositionDone(int channel, void *udata)
    1.23  {
     2.1 --- a/effects_internal.c	Sun Jul 15 10:24:36 2007 +0000
     2.2 +++ b/effects_internal.c	Sun Jul 15 15:43:02 2007 +0000
     2.3 @@ -32,6 +32,9 @@
     2.4  #include <stdlib.h>
     2.5  #include "SDL_mixer.h"
     2.6  
     2.7 +#define __MIX_INTERNAL_EFFECT__
     2.8 +#include "effects_internal.h"
     2.9 +
    2.10  /* Should we favor speed over memory usage and/or quality of output? */
    2.11  int _Mix_effects_max_speed = 0;
    2.12  
    2.13 @@ -41,6 +44,11 @@
    2.14      _Mix_effects_max_speed = (getenv(MIX_EFFECTSMAXSPEED) != NULL);
    2.15  }
    2.16  
    2.17 +void _Mix_DeinitEffects(void)
    2.18 +{
    2.19 +    _Eff_PositionDeinit();
    2.20 +}
    2.21 +
    2.22  
    2.23  void *_Eff_volume_table = NULL;
    2.24  
     3.1 --- a/effects_internal.h	Sun Jul 15 10:24:36 2007 +0000
     3.2 +++ b/effects_internal.h	Sun Jul 15 15:43:02 2007 +0000
     3.3 @@ -41,6 +41,8 @@
     3.4  void *_Eff_build_volume_table_u8(void);
     3.5  void *_Eff_build_volume_table_s8(void);
     3.6  
     3.7 +void _Eff_PositionDeinit(void);
     3.8 +
     3.9  /* Set up for C function definitions, even when using C++ */
    3.10  #ifdef __cplusplus
    3.11  }
     4.1 --- a/mixer.c	Sun Jul 15 10:24:36 2007 +0000
     4.2 +++ b/mixer.c	Sun Jul 15 15:43:02 2007 +0000
     4.3 @@ -35,6 +35,9 @@
     4.4  #include "load_voc.h"
     4.5  #include "load_ogg.h"
     4.6  
     4.7 +#define __MIX_INTERNAL_EFFECT__
     4.8 +#include "effects_internal.h"
     4.9 +
    4.10  /* Magic numbers for various audio file formats */
    4.11  #define RIFF		0x46464952		/* "RIFF" */
    4.12  #define WAVE		0x45564157		/* "WAVE" */
    4.13 @@ -266,8 +269,6 @@
    4.14  }
    4.15  
    4.16  
    4.17 -void _Mix_InitEffects(void);
    4.18 -
    4.19  /* Open the mixer with a certain desired audio format */
    4.20  int Mix_OpenAudio(int frequency, Uint16 format, int nchannels, int chunksize)
    4.21  {
    4.22 @@ -960,6 +961,7 @@
    4.23  			Mix_UnregisterAllEffects(MIX_CHANNEL_POST);
    4.24  			close_music();
    4.25  			Mix_HaltChannel(-1);
    4.26 +			_Eff_PositionDeinit();
    4.27  			SDL_CloseAudio();
    4.28  			free(mix_channel);
    4.29  			mix_channel = NULL;