From 88dcce754067709a494bfd5760caf2303e31e0df Mon Sep 17 00:00:00 2001 From: kazu Date: Sat, 20 Apr 2024 05:20:30 +0000 Subject: [PATCH] Fixed the problem that `ksynth_free` was not releasing the memory of samples and voices. git-svn-id: file:///raid/svn-main/kazu-ksynth/trunk@30 7b47e76f-e598-2f43-bc14-414d160cc389 --- src/ksynth.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ksynth.c b/src/ksynth.c index 2e21040..b33fbf5 100644 --- a/src/ksynth.c +++ b/src/ksynth.c @@ -438,6 +438,27 @@ void ksynth_buffer_free(float* buffer) { void ksynth_free(struct KSynth* ksynth_instance) { if(ksynth_instance != NULL) { + if(ksynth_instance->samples != NULL) { + for(int i = 0; i < 128; i++) { + if(ksynth_instance->samples[i] != NULL) { + free(ksynth_instance->samples[i]->sample); + free(ksynth_instance->samples[i]); + } + } + free(ksynth_instance->samples); + ksynth_instance->samples = NULL; + } + + if(ksynth_instance->voices != NULL) { + for(unsigned long i = 0; i < ksynth_instance->max_polyphony; i++) { + if(ksynth_instance->voices[i] != NULL) { + free(ksynth_instance->voices[i]); + } + } + free(ksynth_instance->voices); + ksynth_instance->voices = NULL; + } + free(ksynth_instance); } } -- 2.43.0