Skip to content

Commit

Permalink
On shutdown, deallocate global memory we might have allocated for eff…
Browse files Browse the repository at this point in the history
…ects.

  Partially fixes Bugzilla #385.
  • Loading branch information
icculus committed Jul 15, 2007
1 parent 3e0ba04 commit 2665f69
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
14 changes: 14 additions & 0 deletions effect_position.c
Expand Up @@ -79,6 +79,20 @@ static position_args **pos_args_array = NULL;
static position_args *pos_args_global = NULL;
static int position_channels = 0;

void _Eff_PositionDeinit(void)
{
int i;
for (i = 0; i < position_channels; i++) {
free(pos_args_array[i]);
}

free(pos_args_global);
pos_args_global = NULL;
free(pos_args_array);
pos_args_array = NULL;
}


/* This just frees up the callback-specific data. */
static void _Eff_PositionDone(int channel, void *udata)
{
Expand Down
8 changes: 8 additions & 0 deletions effects_internal.c
Expand Up @@ -32,6 +32,9 @@
#include <stdlib.h>
#include "SDL_mixer.h"

#define __MIX_INTERNAL_EFFECT__
#include "effects_internal.h"

/* Should we favor speed over memory usage and/or quality of output? */
int _Mix_effects_max_speed = 0;

Expand All @@ -41,6 +44,11 @@ void _Mix_InitEffects(void)
_Mix_effects_max_speed = (getenv(MIX_EFFECTSMAXSPEED) != NULL);
}

void _Mix_DeinitEffects(void)
{
_Eff_PositionDeinit();
}


void *_Eff_volume_table = NULL;

Expand Down
2 changes: 2 additions & 0 deletions effects_internal.h
Expand Up @@ -41,6 +41,8 @@ extern void *_Eff_volume_table;
void *_Eff_build_volume_table_u8(void);
void *_Eff_build_volume_table_s8(void);

void _Eff_PositionDeinit(void);

/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
}
Expand Down
6 changes: 4 additions & 2 deletions mixer.c
Expand Up @@ -35,6 +35,9 @@
#include "load_voc.h"
#include "load_ogg.h"

#define __MIX_INTERNAL_EFFECT__
#include "effects_internal.h"

/* Magic numbers for various audio file formats */
#define RIFF 0x46464952 /* "RIFF" */
#define WAVE 0x45564157 /* "WAVE" */
Expand Down Expand Up @@ -266,8 +269,6 @@ static void PrintFormat(char *title, SDL_AudioSpec *fmt)
}


void _Mix_InitEffects(void);

/* Open the mixer with a certain desired audio format */
int Mix_OpenAudio(int frequency, Uint16 format, int nchannels, int chunksize)
{
Expand Down Expand Up @@ -960,6 +961,7 @@ void Mix_CloseAudio(void)
Mix_UnregisterAllEffects(MIX_CHANNEL_POST);
close_music();
Mix_HaltChannel(-1);
_Eff_PositionDeinit();
SDL_CloseAudio();
free(mix_channel);
mix_channel = NULL;
Expand Down

0 comments on commit 2665f69

Please sign in to comment.