From 323320e7e45326c347be3e3ecb98029723d55eeb Mon Sep 17 00:00:00 2001 From: derselbst Date: Sun, 29 Oct 2017 13:23:08 +0100 Subject: [PATCH] refactor all destructor functions to return void if possible and not crash if called with NULL --- src/bindings/fluid_filerenderer.c | 6 +-- src/bindings/fluid_ladspa.c | 44 ++++++++-------------- src/drivers/fluid_adriver.c | 22 +++++------ src/drivers/fluid_alsa.c | 38 +++++++------------ src/drivers/fluid_aufile.c | 11 ++---- src/drivers/fluid_coreaudio.c | 8 ++-- src/drivers/fluid_coremidi.c | 8 +++- src/drivers/fluid_dart.c | 7 ++-- src/drivers/fluid_dsound.c | 12 ++---- src/drivers/fluid_jack.c | 28 ++++---------- src/drivers/fluid_mdriver.c | 16 ++++---- src/drivers/fluid_midishare.c | 13 ++----- src/drivers/fluid_oss.c | 33 ++++++----------- src/drivers/fluid_portaudio.c | 11 ++---- src/drivers/fluid_pulse.c | 11 ++---- src/drivers/fluid_sndmgr.c | 33 +++++++---------- src/drivers/fluid_winmidi.c | 9 +++-- src/midi/fluid_midi.c | 36 ++++++++---------- src/midi/fluid_midi_router.c | 6 +-- src/midi/fluid_seq.c | 5 +-- src/midi/fluid_seqbind.c | 4 +- src/rvoice/fluid_chorus.c | 14 ++----- src/rvoice/fluid_rev.c | 2 + src/rvoice/fluid_rvoice_event.c | 3 +- src/rvoice/fluid_rvoice_mixer.c | 4 +- src/sfloader/fluid_defsfont.c | 61 ++++++++++++++++--------------- src/sfloader/fluid_defsfont.h | 6 +-- src/synth/fluid_chan.c | 7 ++-- src/synth/fluid_event.c | 1 - src/synth/fluid_synth.c | 16 +++----- src/synth/fluid_tuning.c | 7 +++- src/unused/fluid_rvoice_handler.c | 3 +- src/utils/fluid_list.c | 4 +- src/utils/fluid_ringbuffer.c | 6 +-- src/utils/fluid_settings.c | 11 +++--- src/utils/fluid_sys.c | 24 +++++++----- src/utils/fluid_sys.h | 4 +- 37 files changed, 221 insertions(+), 313 deletions(-) diff --git a/src/bindings/fluid_filerenderer.c b/src/bindings/fluid_filerenderer.c index 9db93ac1..417b34d2 100644 --- a/src/bindings/fluid_filerenderer.c +++ b/src/bindings/fluid_filerenderer.c @@ -342,12 +342,8 @@ void delete_fluid_file_renderer(fluid_file_renderer_t* dev) } #endif - if (dev->buf != NULL) { - FLUID_FREE(dev->buf); - } - + FLUID_FREE(dev->buf); FLUID_FREE(dev); - return; } /** diff --git a/src/bindings/fluid_ladspa.c b/src/bindings/fluid_ladspa.c index ecf803c1..ece30687 100644 --- a/src/bindings/fluid_ladspa.c +++ b/src/bindings/fluid_ladspa.c @@ -203,14 +203,12 @@ fluid_ladspa_fx_t *new_fluid_ladspa_fx(fluid_real_t sample_rate, int audio_group fx->run_finished_mutex = new_fluid_cond_mutex(); if (fx->run_finished_mutex == NULL) { - delete_fluid_ladspa_fx(fx); - return NULL; + goto error_recovery; } fx->run_finished_cond = new_fluid_cond(); if (fx->run_finished_cond == NULL) { - delete_fluid_ladspa_fx(fx); - return NULL; + goto error_recovery; } /* Finally, create the nodes that carry audio in and out of the LADSPA unit. @@ -218,11 +216,14 @@ fluid_ladspa_fx_t *new_fluid_ladspa_fx(fluid_real_t sample_rate, int audio_group * fluid_ladspa_reset but only when this LADSPA fx instance is deleted. */ if (create_input_output_nodes(fx) != FLUID_OK) { - delete_fluid_ladspa_fx(fx); - return NULL; + goto error_recovery; } return fx; + +error_recovery: + delete_fluid_ladspa_fx(fx); + return NULL; } /** @@ -239,6 +240,7 @@ fluid_ladspa_fx_t *new_fluid_ladspa_fx(fluid_real_t sample_rate, int audio_group void delete_fluid_ladspa_fx(fluid_ladspa_fx_t *fx) { int i; + fluid_return_if_fail (fx != NULL); clear_ladspa(fx); @@ -1224,15 +1226,9 @@ new_fluid_ladspa_plugin(fluid_ladspa_fx_t *fx, const fluid_ladspa_lib_t *lib, co static void delete_fluid_ladspa_plugin(fluid_ladspa_plugin_t *plugin) { - if (plugin == NULL) - { - return; - } + fluid_return_if_fail (plugin != NULL); - if (plugin->port_nodes != NULL) - { - FLUID_FREE(plugin->port_nodes); - } + FLUID_FREE(plugin->port_nodes); if (plugin->handle != NULL && plugin->desc != NULL && plugin->desc->cleanup != NULL) { @@ -1299,16 +1295,10 @@ static fluid_ladspa_node_t *new_fluid_ladspa_node(fluid_ladspa_fx_t *fx, const c static void delete_fluid_ladspa_node(fluid_ladspa_node_t *node) { - if (node->buf != NULL) - { - FLUID_FREE(node->buf); - } - - if (node->name != NULL) - { - FLUID_FREE(node->name); - } + fluid_return_if_fail(node != NULL); + FLUID_FREE(node->buf); + FLUID_FREE(node->name); FLUID_FREE(node); } @@ -1374,11 +1364,9 @@ static fluid_ladspa_lib_t *new_fluid_ladspa_lib(fluid_ladspa_fx_t *fx, const cha static void delete_fluid_ladspa_lib(fluid_ladspa_lib_t *lib) { - if (lib->filename != NULL) - { - FLUID_FREE(lib->filename); - } - + fluid_return_if_fail(lib != NULL); + + FLUID_FREE(lib->filename); FLUID_FREE(lib); } diff --git a/src/drivers/fluid_adriver.c b/src/drivers/fluid_adriver.c index bcd8f58e..d4b50df2 100644 --- a/src/drivers/fluid_adriver.c +++ b/src/drivers/fluid_adriver.c @@ -32,7 +32,7 @@ typedef struct _fluid_audriver_definition_t fluid_audio_driver_t* (*new2)(fluid_settings_t* settings, fluid_audio_func_t func, void* data); - int (*free)(fluid_audio_driver_t* driver); + void (*free)(fluid_audio_driver_t* driver); void (*settings)(fluid_settings_t* settings); } fluid_audriver_definition_t; @@ -42,7 +42,7 @@ fluid_audio_driver_t* new_fluid_pulse_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth); fluid_audio_driver_t* new_fluid_pulse_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data); -int delete_fluid_pulse_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_pulse_audio_driver(fluid_audio_driver_t* p); void fluid_pulse_audio_driver_settings(fluid_settings_t* settings); #endif @@ -51,7 +51,7 @@ fluid_audio_driver_t* new_fluid_alsa_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth); fluid_audio_driver_t* new_fluid_alsa_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data); -int delete_fluid_alsa_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_alsa_audio_driver(fluid_audio_driver_t* p); void fluid_alsa_audio_driver_settings(fluid_settings_t* settings); #endif @@ -60,7 +60,7 @@ fluid_audio_driver_t* new_fluid_oss_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth); fluid_audio_driver_t* new_fluid_oss_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data); -int delete_fluid_oss_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_oss_audio_driver(fluid_audio_driver_t* p); void fluid_oss_audio_driver_settings(fluid_settings_t* settings); #endif @@ -70,14 +70,14 @@ fluid_audio_driver_t* new_fluid_core_audio_driver(fluid_settings_t* settings, fluid_audio_driver_t* new_fluid_core_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data); -int delete_fluid_core_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_core_audio_driver(fluid_audio_driver_t* p); void fluid_core_audio_driver_settings(fluid_settings_t* settings); #endif #if DSOUND_SUPPORT fluid_audio_driver_t* new_fluid_dsound_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth); -int delete_fluid_dsound_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_dsound_audio_driver(fluid_audio_driver_t* p); void fluid_dsound_audio_driver_settings(fluid_settings_t* settings); #endif @@ -85,14 +85,14 @@ void fluid_dsound_audio_driver_settings(fluid_settings_t* settings); void fluid_portaudio_driver_settings (fluid_settings_t *settings); fluid_audio_driver_t* new_fluid_portaudio_driver(fluid_settings_t* settings, fluid_synth_t* synth); -int delete_fluid_portaudio_driver(fluid_audio_driver_t* p); +void delete_fluid_portaudio_driver(fluid_audio_driver_t* p); #endif #if JACK_SUPPORT fluid_audio_driver_t* new_fluid_jack_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth); fluid_audio_driver_t* new_fluid_jack_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data); -int delete_fluid_jack_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_jack_audio_driver(fluid_audio_driver_t* p); void fluid_jack_audio_driver_settings(fluid_settings_t* settings); #endif @@ -102,20 +102,20 @@ fluid_audio_driver_t* new_fluid_sndmgr_audio_driver(fluid_settings_t* settings, fluid_audio_driver_t* new_fluid_sndmgr_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data); -int delete_fluid_sndmgr_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_sndmgr_audio_driver(fluid_audio_driver_t* p); #endif #if DART_SUPPORT fluid_audio_driver_t* new_fluid_dart_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth); -int delete_fluid_dart_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_dart_audio_driver(fluid_audio_driver_t* p); void fluid_dart_audio_driver_settings(fluid_settings_t* settings); #endif #if AUFILE_SUPPORT fluid_audio_driver_t* new_fluid_file_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth); -int delete_fluid_file_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_file_audio_driver(fluid_audio_driver_t* p); #endif /* Available audio drivers, listed in order of preference */ diff --git a/src/drivers/fluid_alsa.c b/src/drivers/fluid_alsa.c index 1e88dfc4..c8a2093d 100644 --- a/src/drivers/fluid_alsa.c +++ b/src/drivers/fluid_alsa.c @@ -70,7 +70,7 @@ fluid_audio_driver_t* new_fluid_alsa_audio_driver(fluid_settings_t* settings, fluid_audio_driver_t* new_fluid_alsa_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data); -int delete_fluid_alsa_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_alsa_audio_driver(fluid_audio_driver_t* p); void fluid_alsa_audio_driver_settings(fluid_settings_t* settings); static fluid_thread_return_t fluid_alsa_audio_run_float(void* d); static fluid_thread_return_t fluid_alsa_audio_run_s16(void* d); @@ -117,7 +117,7 @@ fluid_midi_driver_t* new_fluid_alsa_rawmidi_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* event_handler_data); -int delete_fluid_alsa_rawmidi_driver(fluid_midi_driver_t* p); +void delete_fluid_alsa_rawmidi_driver(fluid_midi_driver_t* p); static fluid_thread_return_t fluid_alsa_midi_run(void* d); @@ -138,7 +138,7 @@ typedef struct { fluid_midi_driver_t* new_fluid_alsa_seq_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* data); -int delete_fluid_alsa_seq_driver(fluid_midi_driver_t* p); +void delete_fluid_alsa_seq_driver(fluid_midi_driver_t* p); static fluid_thread_return_t fluid_alsa_seq_run(void* d); /************************************************************** @@ -318,13 +318,11 @@ new_fluid_alsa_audio_driver2(fluid_settings_t* settings, return NULL; } -int delete_fluid_alsa_audio_driver(fluid_audio_driver_t* p) +void delete_fluid_alsa_audio_driver(fluid_audio_driver_t* p) { fluid_alsa_audio_driver_t* dev = (fluid_alsa_audio_driver_t*) p; - if (dev == NULL) { - return FLUID_OK; - } + fluid_return_if_fail(dev != NULL); dev->cont = 0; @@ -335,8 +333,6 @@ int delete_fluid_alsa_audio_driver(fluid_audio_driver_t* p) snd_pcm_close (dev->pcm); FLUID_FREE(dev); - - return FLUID_OK; } /* handle error after an ALSA write call */ @@ -649,15 +645,12 @@ new_fluid_alsa_rawmidi_driver(fluid_settings_t* settings, /* * delete_fluid_alsa_rawmidi_driver */ -int +void delete_fluid_alsa_rawmidi_driver(fluid_midi_driver_t* p) { - fluid_alsa_rawmidi_driver_t* dev; - - dev = (fluid_alsa_rawmidi_driver_t*) p; - if (dev == NULL) { - return FLUID_OK; - } + fluid_alsa_rawmidi_driver_t* dev = (fluid_alsa_rawmidi_driver_t*) p; + + fluid_return_if_fail(dev != NULL); /* cancel the thread and wait for it before cleaning up */ fluid_atomic_int_set(&dev->should_quit, 1); @@ -672,7 +665,6 @@ delete_fluid_alsa_rawmidi_driver(fluid_midi_driver_t* p) delete_fluid_midi_parser(dev->parser); } FLUID_FREE(dev); - return FLUID_OK; } /* @@ -979,15 +971,12 @@ new_fluid_alsa_seq_driver(fluid_settings_t* settings, /* * delete_fluid_alsa_seq_driver */ -int +void delete_fluid_alsa_seq_driver(fluid_midi_driver_t* p) { - fluid_alsa_seq_driver_t* dev; - - dev = (fluid_alsa_seq_driver_t*) p; - if (dev == NULL) { - return FLUID_OK; - } + fluid_alsa_seq_driver_t* dev = (fluid_alsa_seq_driver_t*) p; + + fluid_return_if_fail(dev != NULL); /* cancel the thread and wait for it before cleaning up */ fluid_atomic_int_set(&dev->should_quit, 1); @@ -1002,7 +991,6 @@ delete_fluid_alsa_seq_driver(fluid_midi_driver_t* p) if (dev->pfd) FLUID_FREE (dev->pfd); FLUID_FREE(dev); - return FLUID_OK; } /* diff --git a/src/drivers/fluid_aufile.c b/src/drivers/fluid_aufile.c index 3194e6e7..f7344cad 100644 --- a/src/drivers/fluid_aufile.c +++ b/src/drivers/fluid_aufile.c @@ -51,7 +51,7 @@ typedef struct { fluid_audio_driver_t* new_fluid_file_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth); -int delete_fluid_file_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_file_audio_driver(fluid_audio_driver_t* p); static int fluid_file_audio_run_s16(void* d, unsigned int msec); /************************************************************** @@ -100,13 +100,11 @@ new_fluid_file_audio_driver(fluid_settings_t* settings, return NULL; } -int delete_fluid_file_audio_driver(fluid_audio_driver_t* p) +void delete_fluid_file_audio_driver(fluid_audio_driver_t* p) { fluid_file_audio_driver_t* dev = (fluid_file_audio_driver_t*) p; - - if (dev == NULL) { - return FLUID_OK; - } + + fluid_return_if_fail(dev != NULL); if (dev->timer != NULL) { delete_fluid_timer(dev->timer); @@ -117,7 +115,6 @@ int delete_fluid_file_audio_driver(fluid_audio_driver_t* p) } FLUID_FREE(dev); - return FLUID_OK; } static int fluid_file_audio_run_s16(void* d, unsigned int clock_time) diff --git a/src/drivers/fluid_coreaudio.c b/src/drivers/fluid_coreaudio.c index 0916a7a5..cad98658 100644 --- a/src/drivers/fluid_coreaudio.c +++ b/src/drivers/fluid_coreaudio.c @@ -66,7 +66,7 @@ OSStatus fluid_core_audio_callback (void *data, UInt32 inNumberFrames, AudioBufferList *ioData); -int delete_fluid_core_audio_driver (fluid_audio_driver_t* p); +void delete_fluid_core_audio_driver (fluid_audio_driver_t* p); /************************************************************** @@ -315,13 +315,13 @@ error_recovery: /* * delete_fluid_core_audio_driver */ -int +void delete_fluid_core_audio_driver(fluid_audio_driver_t* p) { fluid_core_audio_driver_t* dev = (fluid_core_audio_driver_t*) p; if (dev == NULL) { - return FLUID_OK; + return; } CloseComponent (dev->outputUnit); @@ -334,8 +334,6 @@ delete_fluid_core_audio_driver(fluid_audio_driver_t* p) } FLUID_FREE(dev); - - return FLUID_OK; } OSStatus diff --git a/src/drivers/fluid_coremidi.c b/src/drivers/fluid_coremidi.c index 0c1b1022..125a7e61 100644 --- a/src/drivers/fluid_coremidi.c +++ b/src/drivers/fluid_coremidi.c @@ -61,7 +61,7 @@ typedef struct { fluid_midi_driver_t* new_fluid_coremidi_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* data); -int delete_fluid_coremidi_driver(fluid_midi_driver_t* p); +void delete_fluid_coremidi_driver(fluid_midi_driver_t* p); void fluid_coremidi_callback(const MIDIPacketList *list, void *p, void *src); void fluid_coremidi_driver_settings(fluid_settings_t* settings) @@ -158,10 +158,14 @@ error_recovery: /* * delete_fluid_coremidi_driver */ -int +void delete_fluid_coremidi_driver(fluid_midi_driver_t* p) { fluid_coremidi_driver_t* dev = (fluid_coremidi_driver_t*) p; + + if(dev == NULL) + return; + if (dev->client != NULL) { MIDIClientDispose(dev->client); } diff --git a/src/drivers/fluid_dart.c b/src/drivers/fluid_dart.c index 6dfe7ae9..5f440851 100644 --- a/src/drivers/fluid_dart.c +++ b/src/drivers/fluid_dart.c @@ -62,7 +62,7 @@ static ULONG (APIENTRY *m_pfnmciSendCommand)(USHORT, USHORT, ULONG, PVOID, USHOR fluid_audio_driver_t* new_fluid_dart_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth); -int delete_fluid_dart_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_dart_audio_driver(fluid_audio_driver_t* p); void fluid_dart_audio_driver_settings(fluid_settings_t* settings); static LONG APIENTRY fluid_dart_audio_run( ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags ); @@ -212,12 +212,12 @@ error_recovery: return NULL; } -int delete_fluid_dart_audio_driver(fluid_audio_driver_t* p) +void delete_fluid_dart_audio_driver(fluid_audio_driver_t* p) { fluid_dart_audio_driver_t* dev = (fluid_dart_audio_driver_t*) p; if (dev == NULL) { - return FLUID_OK; + return; } if (dev->usDeviceID != 0) { @@ -241,7 +241,6 @@ int delete_fluid_dart_audio_driver(fluid_audio_driver_t* p) } FLUID_FREE(dev); - return FLUID_OK; } static LONG APIENTRY fluid_dart_audio_run( ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags ) diff --git a/src/drivers/fluid_dsound.c b/src/drivers/fluid_dsound.c index 3978e0fd..e9ff3aeb 100644 --- a/src/drivers/fluid_dsound.c +++ b/src/drivers/fluid_dsound.c @@ -32,7 +32,7 @@ fluid_audio_driver_t* new_fluid_dsound_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth); -int delete_fluid_dsound_audio_driver(fluid_audio_driver_t* data); +void delete_fluid_dsound_audio_driver(fluid_audio_driver_t* data); DWORD WINAPI fluid_dsound_audio_run(LPVOID lpParameter); HWND fluid_win32_get_window(void); @@ -270,12 +270,12 @@ new_fluid_dsound_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth) } -int delete_fluid_dsound_audio_driver(fluid_audio_driver_t* d) +void delete_fluid_dsound_audio_driver(fluid_audio_driver_t* d) { fluid_dsound_audio_driver_t* dev = (fluid_dsound_audio_driver_t*) d; if (dev == NULL) { - return FLUID_OK; + return; } /* tell the audio thread to stop its loop */ @@ -292,9 +292,7 @@ int delete_fluid_dsound_audio_driver(fluid_audio_driver_t* d) /* release all the allocated ressources */ - if (dev->format != NULL) { FLUID_FREE(dev->format); - } if (dev->sec_buffer != NULL) { IDirectSoundBuffer_Stop(dev->sec_buffer); @@ -308,10 +306,6 @@ int delete_fluid_dsound_audio_driver(fluid_audio_driver_t* d) } FLUID_FREE(dev); - -// fluid_win32_destroy_window(); - - return 0; } DWORD WINAPI fluid_dsound_audio_run(LPVOID lpParameter) diff --git a/src/drivers/fluid_jack.c b/src/drivers/fluid_jack.c index 03853e1e..f6ce48c9 100644 --- a/src/drivers/fluid_jack.c +++ b/src/drivers/fluid_jack.c @@ -91,12 +91,12 @@ static int fluid_jack_client_register_ports (void *driver, int isaudio, fluid_settings_t *settings); fluid_audio_driver_t* new_fluid_jack_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data); -int delete_fluid_jack_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_jack_audio_driver(fluid_audio_driver_t* p); void fluid_jack_driver_shutdown(void *arg); int fluid_jack_driver_srate(jack_nframes_t nframes, void *arg); int fluid_jack_driver_bufsize(jack_nframes_t nframes, void *arg); int fluid_jack_driver_process(jack_nframes_t nframes, void *arg); -int delete_fluid_jack_midi_driver(fluid_midi_driver_t *p); +void delete_fluid_jack_midi_driver(fluid_midi_driver_t *p); static fluid_mutex_t last_client_mutex = G_STATIC_MUTEX_INIT; /* Probably not necessary, but just in case drivers are created by multiple threads */ @@ -491,30 +491,20 @@ new_fluid_jack_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func /* * delete_fluid_jack_audio_driver */ -int +void delete_fluid_jack_audio_driver(fluid_audio_driver_t* p) { fluid_jack_audio_driver_t* dev = (fluid_jack_audio_driver_t*) p; - - if (dev == NULL) return 0; + fluid_return_if_fail (dev != NULL); if (dev->client_ref != NULL) fluid_jack_client_close (dev->client_ref, dev); - if (dev->output_bufs) FLUID_FREE (dev->output_bufs); - - if (dev->output_ports) FLUID_FREE (dev->output_ports); - - if (dev->fx_bufs) FLUID_FREE(dev->fx_bufs); - - if (dev->fx_ports) FLUID_FREE(dev->fx_ports); - FLUID_FREE(dev); - return 0; } /* Process function for audio and MIDI Jack drivers */ @@ -674,20 +664,16 @@ new_fluid_jack_midi_driver (fluid_settings_t *settings, return (fluid_midi_driver_t *)dev; } -int +void delete_fluid_jack_midi_driver(fluid_midi_driver_t *p) { fluid_jack_midi_driver_t *dev = (fluid_jack_midi_driver_t *)p; - - if (dev == NULL) return FLUID_OK; + fluid_return_if_fail (dev != NULL); if (dev->client_ref != NULL) fluid_jack_client_close (dev->client_ref, dev); - if (dev->parser != NULL) delete_fluid_midi_parser (dev->parser); - + FLUID_FREE (dev); - - return FLUID_OK; } diff --git a/src/drivers/fluid_mdriver.c b/src/drivers/fluid_mdriver.c index 8d8cf382..16001af9 100644 --- a/src/drivers/fluid_mdriver.c +++ b/src/drivers/fluid_mdriver.c @@ -27,13 +27,13 @@ fluid_midi_driver_t* new_fluid_alsa_rawmidi_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* event_handler_data); -int delete_fluid_alsa_rawmidi_driver(fluid_midi_driver_t* p); +void delete_fluid_alsa_rawmidi_driver(fluid_midi_driver_t* p); void fluid_alsa_rawmidi_driver_settings(fluid_settings_t* settings); fluid_midi_driver_t* new_fluid_alsa_seq_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* event_handler_data); -int delete_fluid_alsa_seq_driver(fluid_midi_driver_t* p); +void delete_fluid_alsa_seq_driver(fluid_midi_driver_t* p); void fluid_alsa_seq_driver_settings(fluid_settings_t* settings); #endif @@ -43,7 +43,7 @@ void fluid_jack_midi_driver_settings (fluid_settings_t *settings); fluid_midi_driver_t *new_fluid_jack_midi_driver (fluid_settings_t *settings, handle_midi_event_func_t handler, void *data); -int delete_fluid_jack_midi_driver(fluid_midi_driver_t *p); +void delete_fluid_jack_midi_driver(fluid_midi_driver_t *p); #endif /* OSS */ @@ -51,7 +51,7 @@ int delete_fluid_jack_midi_driver(fluid_midi_driver_t *p); fluid_midi_driver_t* new_fluid_oss_midi_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* event_handler_data); -int delete_fluid_oss_midi_driver(fluid_midi_driver_t* p); +void delete_fluid_oss_midi_driver(fluid_midi_driver_t* p); void fluid_oss_midi_driver_settings(fluid_settings_t* settings); #endif @@ -60,7 +60,7 @@ void fluid_oss_midi_driver_settings(fluid_settings_t* settings); fluid_midi_driver_t* new_fluid_winmidi_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* event_handler_data); -int delete_fluid_winmidi_driver(fluid_midi_driver_t* p); +void delete_fluid_winmidi_driver(fluid_midi_driver_t* p); void fluid_winmidi_midi_driver_settings(fluid_settings_t* settings); #endif @@ -69,7 +69,7 @@ void fluid_winmidi_midi_driver_settings(fluid_settings_t* settings); fluid_midi_driver_t* new_fluid_midishare_midi_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* event_handler_data); -int delete_fluid_midishare_midi_driver(fluid_midi_driver_t* p); +void delete_fluid_midishare_midi_driver(fluid_midi_driver_t* p); #endif /* definitions for the CoreMidi driver */ @@ -77,7 +77,7 @@ int delete_fluid_midishare_midi_driver(fluid_midi_driver_t* p); fluid_midi_driver_t* new_fluid_coremidi_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* event_handler_data); -int delete_fluid_coremidi_driver(fluid_midi_driver_t* p); +void delete_fluid_coremidi_driver(fluid_midi_driver_t* p); void fluid_coremidi_driver_settings(fluid_settings_t* settings); #endif @@ -90,7 +90,7 @@ struct fluid_mdriver_definition_t { fluid_midi_driver_t* (*new)(fluid_settings_t* settings, handle_midi_event_func_t event_handler, void* event_handler_data); - int (*free)(fluid_midi_driver_t* p); + void (*free)(fluid_midi_driver_t* p); void (*settings)(fluid_settings_t* settings); }; diff --git a/src/drivers/fluid_midishare.c b/src/drivers/fluid_midishare.c index 81cb7b1e..f5f60ea3 100644 --- a/src/drivers/fluid_midishare.c +++ b/src/drivers/fluid_midishare.c @@ -69,7 +69,7 @@ fluid_midi_driver_t* new_fluid_midishare_midi_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* data); -int delete_fluid_midishare_midi_driver(fluid_midi_driver_t* p); +void delete_fluid_midishare_midi_driver(fluid_midi_driver_t* p); int fluid_midishare_midi_driver_status(fluid_midi_driver_t* p); static void fluid_midishare_midi_driver_receive(short ref); @@ -156,14 +156,10 @@ new_fluid_midishare_midi_driver(fluid_settings_t* settings, /* * delete_fluid_midishare_midi_driver */ -int delete_fluid_midishare_midi_driver(fluid_midi_driver_t* p) +void delete_fluid_midishare_midi_driver(fluid_midi_driver_t* p) { - fluid_midishare_midi_driver_t* dev; - - dev = (fluid_midishare_midi_driver_t*) p; - if (dev == NULL) { - return FLUID_OK; - } + fluid_midishare_midi_driver_t* dev = (fluid_midishare_midi_driver_t*) p; + fluid_return_if_fail(dev != NULL); if (dev->filter) MidiFreeFilter(dev->filter); @@ -183,7 +179,6 @@ int delete_fluid_midishare_midi_driver(fluid_midi_driver_t* p) dev->status = FLUID_MIDI_DONE; FLUID_FREE(dev); - return FLUID_OK; } diff --git a/src/drivers/fluid_oss.c b/src/drivers/fluid_oss.c index 05629da6..8e00f519 100644 --- a/src/drivers/fluid_oss.c +++ b/src/drivers/fluid_oss.c @@ -73,7 +73,7 @@ typedef struct { float* buffers[2]; } fluid_oss_audio_driver_t; -int delete_fluid_oss_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_oss_audio_driver(fluid_audio_driver_t* p); /* local utilities */ static int fluid_oss_set_queue_size(fluid_oss_audio_driver_t* dev, int ss, int ch, int qs, int bs); @@ -93,7 +93,7 @@ typedef struct { fluid_midi_driver_t* new_fluid_oss_midi_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* data); -int delete_fluid_oss_midi_driver(fluid_midi_driver_t* p); +void delete_fluid_oss_midi_driver(fluid_midi_driver_t* p); int fluid_oss_midi_driver_status(fluid_midi_driver_t* p); static fluid_thread_return_t fluid_oss_midi_run(void* d); @@ -368,14 +368,11 @@ error_recovery: /* * delete_fluid_oss_audio_driver */ -int +void delete_fluid_oss_audio_driver(fluid_audio_driver_t* p) { fluid_oss_audio_driver_t* dev = (fluid_oss_audio_driver_t*) p; - - if (dev == NULL) { - return FLUID_OK; - } + fluid_return_if_fail(dev != NULL); dev->cont = 0; @@ -385,11 +382,9 @@ delete_fluid_oss_audio_driver(fluid_audio_driver_t* p) if (dev->dspfd >= 0) { close(dev->dspfd); } - if (dev->buffer != NULL) { - FLUID_FREE(dev->buffer); - } + + FLUID_FREE(dev->buffer); FLUID_FREE(dev); - return FLUID_OK; } /** @@ -596,15 +591,11 @@ new_fluid_oss_midi_driver(fluid_settings_t* settings, /* * delete_fluid_oss_midi_driver */ -int +void delete_fluid_oss_midi_driver(fluid_midi_driver_t* p) { - fluid_oss_midi_driver_t* dev; - - dev = (fluid_oss_midi_driver_t*) p; - if (dev == NULL) { - return FLUID_OK; - } + fluid_oss_midi_driver_t* dev = (fluid_oss_midi_driver_t*) p; + fluid_return_if_fail(dev != NULL); /* cancel the thread and wait for it before cleaning up */ dev->status = FLUID_MIDI_DONE; @@ -615,11 +606,9 @@ delete_fluid_oss_midi_driver(fluid_midi_driver_t* p) if (dev->fd >= 0) { close(dev->fd); } - if (dev->parser != NULL) { - delete_fluid_midi_parser(dev->parser); - } + + delete_fluid_midi_parser(dev->parser); FLUID_FREE(dev); - return FLUID_OK; } /* diff --git a/src/drivers/fluid_portaudio.c b/src/drivers/fluid_portaudio.c index 0d1e9a72..798ac6c9 100644 --- a/src/drivers/fluid_portaudio.c +++ b/src/drivers/fluid_portaudio.c @@ -57,7 +57,7 @@ static int fluid_portaudio_run (const void *input, void *output, unsigned long frameCount, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void *userData); -int delete_fluid_portaudio_driver (fluid_audio_driver_t *p); +void delete_fluid_portaudio_driver (fluid_audio_driver_t *p); #define PORTAUDIO_DEFAULT_DEVICE "PortAudio Default" @@ -249,14 +249,12 @@ fluid_portaudio_run (const void *input, void *output, unsigned long frameCount, /* * delete_fluid_portaudio_driver */ -int +void delete_fluid_portaudio_driver(fluid_audio_driver_t *p) { - fluid_portaudio_driver_t* dev; + fluid_portaudio_driver_t* dev = (fluid_portaudio_driver_t*)p; PaError err; - - dev = (fluid_portaudio_driver_t*)p; - if (dev == NULL) return FLUID_OK; + fluid_return_if_fail(dev != NULL); /* PortAudio section */ if (dev->stream) Pa_CloseStream (dev->stream); @@ -267,7 +265,6 @@ delete_fluid_portaudio_driver(fluid_audio_driver_t *p) printf ("PortAudio termination error: %s\n", Pa_GetErrorText (err) ); FLUID_FREE (dev); - return FLUID_OK; } #endif /*#if PORTAUDIO_SUPPORT */ diff --git a/src/drivers/fluid_pulse.c b/src/drivers/fluid_pulse.c index 4ea00621..08c6a66a 100644 --- a/src/drivers/fluid_pulse.c +++ b/src/drivers/fluid_pulse.c @@ -53,7 +53,7 @@ fluid_audio_driver_t* new_fluid_pulse_audio_driver(fluid_settings_t* settings, fluid_synth_t* synth); fluid_audio_driver_t* new_fluid_pulse_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data); -int delete_fluid_pulse_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_pulse_audio_driver(fluid_audio_driver_t* p); void fluid_pulse_audio_driver_settings(fluid_settings_t* settings); static fluid_thread_return_t fluid_pulse_audio_run(void* d); static fluid_thread_return_t fluid_pulse_audio_run2(void* d); @@ -174,13 +174,10 @@ new_fluid_pulse_audio_driver2(fluid_settings_t* settings, return NULL; } -int delete_fluid_pulse_audio_driver(fluid_audio_driver_t* p) +void delete_fluid_pulse_audio_driver(fluid_audio_driver_t* p) { fluid_pulse_audio_driver_t* dev = (fluid_pulse_audio_driver_t*) p; - - if (dev == NULL) { - return FLUID_OK; - } + fluid_return_if_fail(dev != NULL); dev->cont = 0; @@ -191,8 +188,6 @@ int delete_fluid_pulse_audio_driver(fluid_audio_driver_t* p) pa_simple_free(dev->pa_handle); FLUID_FREE(dev); - - return FLUID_OK; } /* Thread without audio callback, more efficient */ diff --git a/src/drivers/fluid_sndmgr.c b/src/drivers/fluid_sndmgr.c index 816942d7..9ea62e1e 100644 --- a/src/drivers/fluid_sndmgr.c +++ b/src/drivers/fluid_sndmgr.c @@ -52,7 +52,7 @@ fluid_audio_driver_t* new_fluid_sndmgr_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func, void* data); -int delete_fluid_sndmgr_audio_driver(fluid_audio_driver_t* p); +void delete_fluid_sndmgr_audio_driver(fluid_audio_driver_t* p); void pascal fluid_sndmgr_callback(SndChannelPtr chan, SndDoubleBufferPtr doubleBuffer); Fixed fluid_sndmgr_double_to_fix(long double theLD); @@ -226,36 +226,29 @@ new_fluid_sndmgr_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t fu /* * delete_fluid_sndmgr_audio_driver */ -int delete_fluid_sndmgr_audio_driver(fluid_audio_driver_t* p) +void delete_fluid_sndmgr_audio_driver(fluid_audio_driver_t* p) { fluid_sndmgr_audio_driver_t* dev = (fluid_sndmgr_audio_driver_t*) p; + fluid_return_if_fail(dev != NULL); - if (dev != NULL) { if (dev->channel != NULL) { SndDisposeChannel(dev->channel, 1); } + if (dev->doubleCallbackProc != NULL) { DisposeRoutineDescriptor(dev->doubleCallbackProc); } - if (dev->doubleHeader != NULL) { - if(dev->doubleHeader->dbhBufferPtr[0] != NULL) { - FLUID_FREE(dev->doubleHeader->dbhBufferPtr[0]); - } - if (dev->doubleHeader->dbhBufferPtr[1] != NULL) { - FLUID_FREE(dev->doubleHeader->dbhBufferPtr[1]); - } - FLUID_FREE(dev->doubleHeader); + + if (dev->doubleHeader != NULL) + { + FLUID_FREE(dev->doubleHeader->dbhBufferPtr[0]); + FLUID_FREE(dev->doubleHeader->dbhBufferPtr[1]); + FLUID_FREE(dev->doubleHeader); } - if (dev->convbuffers[0] != NULL) { - FLUID_FREE(dev->convbuffers[0]); - } - if (dev->convbuffers[1] != NULL) { - FLUID_FREE(dev->convbuffers[1]); - } - + + FLUID_FREE(dev->convbuffers[0]); + FLUID_FREE(dev->convbuffers[1]); FLUID_FREE(dev); - } - return 0; } /* diff --git a/src/drivers/fluid_winmidi.c b/src/drivers/fluid_winmidi.c index 677dae5f..1242225d 100644 --- a/src/drivers/fluid_winmidi.c +++ b/src/drivers/fluid_winmidi.c @@ -72,7 +72,7 @@ static char fluid_winmidi_error_buffer[256]; fluid_midi_driver_t* new_fluid_winmidi_driver(fluid_settings_t* settings, handle_midi_event_func_t handler, void* data); -int delete_fluid_winmidi_driver(fluid_midi_driver_t* p); +void delete_fluid_winmidi_driver(fluid_midi_driver_t* p); void CALLBACK fluid_winmidi_callback(HMIDIIN hmi, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR msg, DWORD_PTR extra); @@ -243,10 +243,14 @@ new_fluid_winmidi_driver(fluid_settings_t* settings, /* * delete_fluid_winmidi_driver */ -int +void delete_fluid_winmidi_driver(fluid_midi_driver_t* p) { fluid_winmidi_driver_t* dev = (fluid_winmidi_driver_t*) p; + + if(dev == NULL) + return; + if (dev->hmidiin != NULL) { fluid_atomic_int_set (&dev->closing, TRUE); @@ -268,7 +272,6 @@ delete_fluid_winmidi_driver(fluid_midi_driver_t* p) if (dev->cond) delete_fluid_cond (dev->cond); FLUID_FREE(dev); - return 0; } void CALLBACK diff --git a/src/midi/fluid_midi.c b/src/midi/fluid_midi.c index e589d5cb..f49670ff 100644 --- a/src/midi/fluid_midi.c +++ b/src/midi/fluid_midi.c @@ -118,11 +118,9 @@ fluid_file_read_full(fluid_file fp, size_t* length) void delete_fluid_midi_file (fluid_midi_file *mf) { - if (mf == NULL) { - return; - } + fluid_return_if_fail(mf != NULL); + FLUID_FREE(mf); - return; } /* @@ -801,10 +799,11 @@ new_fluid_midi_event () * @param evt MIDI event structure * @return Always returns #FLUID_OK */ -int +void delete_fluid_midi_event(fluid_midi_event_t *evt) { fluid_midi_event_t *temp; + fluid_return_if_fail(evt != NULL); while (evt) { temp = evt->next; @@ -816,7 +815,6 @@ delete_fluid_midi_event(fluid_midi_event_t *evt) FLUID_FREE(evt); evt = temp; } - return FLUID_OK; } /** @@ -1061,17 +1059,14 @@ new_fluid_track(int num) /* * delete_fluid_track */ -int +void delete_fluid_track(fluid_track_t *track) { - if (track->name != NULL) { - FLUID_FREE(track->name); - } - if (track->first != NULL) { - delete_fluid_midi_event(track->first); - } + fluid_return_if_fail(track != NULL); + + FLUID_FREE(track->name); + delete_fluid_midi_event(track->first); FLUID_FREE(track); - return FLUID_OK; } /* @@ -1292,15 +1287,14 @@ new_fluid_player(fluid_synth_t *synth) * @param player MIDI player instance * @return Always returns #FLUID_OK */ -int +void delete_fluid_player(fluid_player_t *player) { fluid_list_t *q; fluid_playlist_item* pi; - if (player == NULL) { - return FLUID_OK; - } + fluid_return_if_fail(player != NULL); + fluid_player_stop(player); fluid_player_reset(player); @@ -1315,7 +1309,6 @@ delete_fluid_player(fluid_player_t *player) } FLUID_FREE(player); - return FLUID_OK; } /** @@ -1862,11 +1855,12 @@ new_fluid_midi_parser () /* * delete_fluid_midi_parser */ -int +void delete_fluid_midi_parser(fluid_midi_parser_t *parser) { + fluid_return_if_fail(parser != NULL); + FLUID_FREE(parser); - return FLUID_OK; } /** diff --git a/src/midi/fluid_midi_router.c b/src/midi/fluid_midi_router.c index 215d692e..b0b9555b 100644 --- a/src/midi/fluid_midi_router.c +++ b/src/midi/fluid_midi_router.c @@ -125,14 +125,14 @@ new_fluid_midi_router(fluid_settings_t *settings, handle_midi_event_func_t handl * @return Returns #FLUID_OK on success, #FLUID_FAILED otherwise (only if NULL * \a router passed really) */ -int +void delete_fluid_midi_router (fluid_midi_router_t *router) { fluid_midi_router_rule_t *rule; fluid_midi_router_rule_t *next_rule; int i; - fluid_return_val_if_fail (router != NULL, FLUID_FAILED); + fluid_return_if_fail (router != NULL); for (i = 0; i < FLUID_MIDI_ROUTER_RULE_COUNT; i++) { @@ -145,8 +145,6 @@ delete_fluid_midi_router (fluid_midi_router_t *router) fluid_mutex_destroy (router->rules_mutex); FLUID_FREE (router); - - return FLUID_OK; } /** diff --git a/src/midi/fluid_seq.c b/src/midi/fluid_seq.c index a3b96191..c0b5996a 100644 --- a/src/midi/fluid_seq.c +++ b/src/midi/fluid_seq.c @@ -154,10 +154,7 @@ new_fluid_sequencer2 (int use_system_timer) void delete_fluid_sequencer (fluid_sequencer_t* seq) { - - if (seq == NULL) { - return; - } + fluid_return_if_fail(seq != NULL); /* cleanup clients */ while (seq->clients) { diff --git a/src/midi/fluid_seqbind.c b/src/midi/fluid_seqbind.c index 9a444ce6..b94872d2 100644 --- a/src/midi/fluid_seqbind.c +++ b/src/midi/fluid_seqbind.c @@ -53,9 +53,7 @@ void fluid_seq_fluidsynth_callback(unsigned int time, fluid_event_t* event, flui void delete_fluid_seqbind(fluid_seqbind_t* seqbind) { - if (seqbind == NULL) { - return; - } + fluid_return_if_fail(seqbind != NULL); if ((seqbind->client_id != -1) && (seqbind->seq != NULL)) { fluid_sequencer_unregister_client(seqbind->seq, seqbind->client_id); diff --git a/src/rvoice/fluid_chorus.c b/src/rvoice/fluid_chorus.c index 96f50cbb..f6270ed7 100644 --- a/src/rvoice/fluid_chorus.c +++ b/src/rvoice/fluid_chorus.c @@ -205,19 +205,11 @@ new_fluid_chorus(fluid_real_t sample_rate) void delete_fluid_chorus(fluid_chorus_t* chorus) { - if (chorus == NULL) { - return; - } - - if (chorus->chorusbuf != NULL) { + fluid_return_if_fail(chorus != NULL); + FLUID_FREE(chorus->chorusbuf); - } - - if (chorus->lookup_tab != NULL) { FLUID_FREE(chorus->lookup_tab); - } - - FLUID_FREE(chorus); + FLUID_FREE(chorus); } int diff --git a/src/rvoice/fluid_rev.c b/src/rvoice/fluid_rev.c index 51b0e79c..f76b9bcb 100644 --- a/src/rvoice/fluid_rev.c +++ b/src/rvoice/fluid_rev.c @@ -334,6 +334,8 @@ void delete_fluid_revmodel(fluid_revmodel_t* rev) { int i; + fluid_return_if_fail(rev != NULL); + for (i = 0; i < numcombs;i++) { fluid_comb_release(&rev->combL[i]); fluid_comb_release(&rev->combR[i]); diff --git a/src/rvoice/fluid_rvoice_event.c b/src/rvoice/fluid_rvoice_event.c index a0f8147c..5edf4fab 100644 --- a/src/rvoice/fluid_rvoice_event.c +++ b/src/rvoice/fluid_rvoice_event.c @@ -280,7 +280,8 @@ fluid_rvoice_eventhandler_dispatch_all(fluid_rvoice_eventhandler_t* handler) void delete_fluid_rvoice_eventhandler(fluid_rvoice_eventhandler_t* handler) { - if (handler == NULL) return; + fluid_return_if_fail(handler != NULL); + delete_fluid_rvoice_mixer(handler->mixer); delete_fluid_ringbuffer(handler->queue); delete_fluid_ringbuffer(handler->finished_voices); diff --git a/src/rvoice/fluid_rvoice_mixer.c b/src/rvoice/fluid_rvoice_mixer.c index 8fc487e1..bad02c92 100644 --- a/src/rvoice/fluid_rvoice_mixer.c +++ b/src/rvoice/fluid_rvoice_mixer.c @@ -603,8 +603,8 @@ fluid_mixer_buffers_free(fluid_mixer_buffers_t* buffers) void delete_fluid_rvoice_mixer(fluid_rvoice_mixer_t* mixer) { - if (!mixer) - return; + fluid_return_if_fail(mixer != NULL); + fluid_rvoice_mixer_set_threads(mixer, 0, 0); #ifdef ENABLE_MIXER_THREADS if (mixer->thread_ready) diff --git a/src/sfloader/fluid_defsfont.c b/src/sfloader/fluid_defsfont.c index 2bf81518..4bac8728 100644 --- a/src/sfloader/fluid_defsfont.c +++ b/src/sfloader/fluid_defsfont.c @@ -54,10 +54,10 @@ fluid_sfloader_t* new_fluid_defsfloader(fluid_settings_t* settings) int delete_fluid_defsfloader(fluid_sfloader_t* loader) { - if (loader) { + fluid_return_val_if_fail(loader != NULL, 0); + FLUID_FREE(loader); - } - return FLUID_OK; + return 0; } fluid_sfont_t* fluid_defsfloader_load(fluid_sfloader_t* loader, const char* filename) @@ -101,7 +101,7 @@ fluid_sfont_t* fluid_defsfloader_load(fluid_sfloader_t* loader, const char* file int fluid_defsfont_sfont_delete(fluid_sfont_t* sfont) { - if (delete_fluid_defsfont(sfont->data) != 0) { + if (delete_fluid_defsfont(sfont->data) != FLUID_OK) { return -1; } FLUID_FREE(sfont); @@ -496,11 +496,14 @@ int delete_fluid_defsfont(fluid_defsfont_t* sfont) fluid_defpreset_t* preset; fluid_sample_t* sample; + if(sfont == NULL) + return FLUID_OK; + /* Check that no samples are currently used */ for (list = sfont->sample; list; list = fluid_list_next(list)) { sample = (fluid_sample_t*) fluid_list_get(list); if (fluid_sample_refcount(sample) != 0) { - return -1; + return FLUID_FAILED; } } @@ -748,18 +751,17 @@ delete_fluid_defpreset(fluid_defpreset_t* preset) { int err = FLUID_OK; fluid_preset_zone_t* zone; - if (preset->global_zone != NULL) { - if (delete_fluid_preset_zone(preset->global_zone) != FLUID_OK) { - err = FLUID_FAILED; - } + + if(preset == NULL) + return err; + + delete_fluid_preset_zone(preset->global_zone); preset->global_zone = NULL; - } + zone = preset->zone; while (zone != NULL) { preset->zone = zone->next; - if (delete_fluid_preset_zone(zone) != FLUID_OK) { - err = FLUID_FAILED; - } + delete_fluid_preset_zone(zone); zone = preset->zone; } FLUID_FREE(preset); @@ -1161,11 +1163,14 @@ new_fluid_preset_zone(char *name) /* * delete_fluid_preset_zone */ -int +void delete_fluid_preset_zone(fluid_preset_zone_t* zone) { fluid_mod_t *mod, *tmp; + if(zone == NULL) + return; + mod = zone->mod; while (mod) /* delete the modulators */ { @@ -1177,7 +1182,6 @@ delete_fluid_preset_zone(fluid_preset_zone_t* zone) if (zone->name) FLUID_FREE (zone->name); if (zone->inst) delete_fluid_inst (zone->inst); FLUID_FREE(zone); - return FLUID_OK; } /* @@ -1403,18 +1407,14 @@ delete_fluid_inst(fluid_inst_t* inst) { fluid_inst_zone_t* zone; int err = FLUID_OK; - if (inst->global_zone != NULL) { - if (delete_fluid_inst_zone(inst->global_zone) != FLUID_OK) { - err = FLUID_FAILED; - } + + delete_fluid_inst_zone(inst->global_zone); inst->global_zone = NULL; - } + zone = inst->zone; while (zone != NULL) { inst->zone = zone->next; - if (delete_fluid_inst_zone(zone) != FLUID_OK) { - err = FLUID_FAILED; - } + delete_fluid_inst_zone(zone); zone = inst->zone; } FLUID_FREE(inst); @@ -1556,11 +1556,14 @@ new_fluid_inst_zone(char* name) /* * delete_fluid_inst_zone */ -int +void delete_fluid_inst_zone(fluid_inst_zone_t* zone) { fluid_mod_t *mod, *tmp; + if(zone == NULL) + return; + mod = zone->mod; while (mod) /* delete the modulators */ { @@ -1569,9 +1572,8 @@ delete_fluid_inst_zone(fluid_inst_zone_t* zone) fluid_mod_delete (tmp); } - if (zone->name) FLUID_FREE (zone->name); + FLUID_FREE (zone->name); FLUID_FREE(zone); - return FLUID_OK; } /* @@ -1802,19 +1804,20 @@ new_fluid_sample() /* * delete_fluid_sample */ -int +void delete_fluid_sample(fluid_sample_t* sample) { + if(sample == NULL) + return; + if (sample->sampletype & FLUID_SAMPLETYPE_OGG_VORBIS) { #if LIBSNDFILE_SUPPORT - if (sample->data) FLUID_FREE(sample->data); #endif } FLUID_FREE(sample); - return FLUID_OK; } /* diff --git a/src/sfloader/fluid_defsfont.h b/src/sfloader/fluid_defsfont.h index 3ee4d9b8..41cb6a20 100644 --- a/src/sfloader/fluid_defsfont.h +++ b/src/sfloader/fluid_defsfont.h @@ -445,7 +445,7 @@ struct _fluid_preset_zone_t }; fluid_preset_zone_t* new_fluid_preset_zone(char* name); -int delete_fluid_preset_zone(fluid_preset_zone_t* zone); +void delete_fluid_preset_zone(fluid_preset_zone_t* zone); fluid_preset_zone_t* fluid_preset_zone_next(fluid_preset_zone_t* preset); int fluid_preset_zone_import_sfont(fluid_preset_zone_t* zone, SFZone* sfzone, fluid_defsfont_t* sfont); int fluid_preset_zone_inside_range(fluid_preset_zone_t* zone, int key, int vel); @@ -486,7 +486,7 @@ struct _fluid_inst_zone_t }; fluid_inst_zone_t* new_fluid_inst_zone(char* name); -int delete_fluid_inst_zone(fluid_inst_zone_t* zone); +void delete_fluid_inst_zone(fluid_inst_zone_t* zone); fluid_inst_zone_t* fluid_inst_zone_next(fluid_inst_zone_t* zone); int fluid_inst_zone_import_sfont(fluid_inst_zone_t* zone, SFZone *sfzone, fluid_defsfont_t* sfont); int fluid_inst_zone_inside_range(fluid_inst_zone_t* zone, int key, int vel); @@ -495,7 +495,7 @@ fluid_sample_t* fluid_inst_zone_get_sample(fluid_inst_zone_t* zone); fluid_sample_t* new_fluid_sample(void); -int delete_fluid_sample(fluid_sample_t* sample); +void delete_fluid_sample(fluid_sample_t* sample); int fluid_sample_import_sfont(fluid_sample_t* sample, SFSample* sfsample, fluid_defsfont_t* sfont); int fluid_sample_in_rom(fluid_sample_t* sample); diff --git a/src/synth/fluid_chan.c b/src/synth/fluid_chan.c index 418da1e2..a615393e 100644 --- a/src/synth/fluid_chan.c +++ b/src/synth/fluid_chan.c @@ -174,12 +174,13 @@ fluid_channel_init_ctrl(fluid_channel_t* chan, int is_all_ctrl_off) } /* Only called by delete_fluid_synth(), so no need to queue a preset free event */ -int +void delete_fluid_channel(fluid_channel_t* chan) { - if (chan->preset) delete_fluid_preset (chan->preset); + fluid_return_if_fail(chan != NULL); + + delete_fluid_preset (chan->preset); FLUID_FREE(chan); - return FLUID_OK; } /* FIXME - Calls fluid_channel_init() potentially in synthesis context */ diff --git a/src/synth/fluid_event.c b/src/synth/fluid_event.c index 0a6f5fa1..83438bc3 100644 --- a/src/synth/fluid_event.c +++ b/src/synth/fluid_event.c @@ -75,7 +75,6 @@ new_fluid_event() void delete_fluid_event(fluid_event_t* evt) { - if (evt == NULL) { return; } diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index dfbc4732..9eef9ade 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -501,19 +501,19 @@ fluid_sample_timer_t* new_fluid_sample_timer(fluid_synth_t* synth, fluid_timer_c return result; } -int delete_fluid_sample_timer(fluid_synth_t* synth, fluid_sample_timer_t* timer) +void delete_fluid_sample_timer(fluid_synth_t* synth, fluid_sample_timer_t* timer) { + fluid_return_if_fail(synth != NULL); + fluid_return_if_fail(timer != NULL); + fluid_sample_timer_t** ptr = &synth->sample_timers; while (*ptr) { if (*ptr == timer) { *ptr = timer->next; FLUID_FREE(timer); - return FLUID_OK; } ptr = &((*ptr)->next); } - FLUID_LOG(FLUID_ERR,"delete_fluid_sample_timer failed, no timer found"); - return FLUID_FAILED; } @@ -821,7 +821,7 @@ new_fluid_synth(fluid_settings_t *settings) * @note Other users of a synthesizer instance, such as audio and MIDI drivers, * should be deleted prior to freeing the FluidSynth instance. */ -int +void delete_fluid_synth(fluid_synth_t* synth) { int i, k; @@ -831,9 +831,7 @@ delete_fluid_synth(fluid_synth_t* synth) fluid_mod_t* default_mod; fluid_mod_t* mod; - if (synth == NULL) { - return FLUID_OK; - } + fluid_return_if_fail(synth != NULL); fluid_profiling_print(); @@ -947,8 +945,6 @@ delete_fluid_synth(fluid_synth_t* synth) fluid_rec_mutex_destroy(synth->mutex); FLUID_FREE(synth); - - return FLUID_OK; } /** diff --git a/src/synth/fluid_tuning.c b/src/synth/fluid_tuning.c index 6783c7b7..d0188a35 100644 --- a/src/synth/fluid_tuning.c +++ b/src/synth/fluid_tuning.c @@ -94,8 +94,11 @@ fluid_tuning_duplicate (fluid_tuning_t *tuning) void delete_fluid_tuning (fluid_tuning_t *tuning) { - if (tuning->name) FLUID_FREE (tuning->name); - FLUID_FREE (tuning); + if(tuning != NULL) + { + if (tuning->name) FLUID_FREE (tuning->name); + FLUID_FREE (tuning); + } } /* Add a reference to a tuning object */ diff --git a/src/unused/fluid_rvoice_handler.c b/src/unused/fluid_rvoice_handler.c index c3c952bf..db0e4522 100644 --- a/src/unused/fluid_rvoice_handler.c +++ b/src/unused/fluid_rvoice_handler.c @@ -38,8 +38,7 @@ fluid_rvoice_handler_t* new_fluid_rvoice_handler(void) void delete_fluid_rvoice_handler(fluid_rvoice_handler_t* handler) { - if (handler == NULL) - return; + fluid_return_if_fail(handler != NULL); #if 0 FLUID_FREE(handler->finished_voices); diff --git a/src/utils/fluid_list.c b/src/utils/fluid_list.c index 97c1bbe7..b845a779 100644 --- a/src/utils/fluid_list.c +++ b/src/utils/fluid_list.c @@ -42,6 +42,8 @@ new_fluid_list(void) void delete_fluid_list(fluid_list_t *list) { + fluid_return_if_fail(list != NULL); + fluid_list_t *next; while (list) { next = list->next; @@ -53,9 +55,7 @@ delete_fluid_list(fluid_list_t *list) void delete1_fluid_list(fluid_list_t *list) { - if (list) { FLUID_FREE(list); - } } fluid_list_t* diff --git a/src/utils/fluid_ringbuffer.c b/src/utils/fluid_ringbuffer.c index 512c95a3..d94e9c84 100644 --- a/src/utils/fluid_ringbuffer.c +++ b/src/utils/fluid_ringbuffer.c @@ -57,8 +57,8 @@ new_fluid_ringbuffer (int count, int elementsize) if (!queue->array) { - FLUID_FREE (queue); FLUID_LOG (FLUID_ERR, "Out of memory"); + delete_fluid_ringbuffer(queue); return NULL; } @@ -84,9 +84,7 @@ new_fluid_ringbuffer (int count, int elementsize) void delete_fluid_ringbuffer (fluid_ringbuffer_t *queue) { - if(queue != NULL) - { + fluid_return_if_fail(queue != NULL); FLUID_FREE (queue->array); FLUID_FREE (queue); - } } diff --git a/src/utils/fluid_settings.c b/src/utils/fluid_settings.c index ff111d38..25dc7f0a 100644 --- a/src/utils/fluid_settings.c +++ b/src/utils/fluid_settings.c @@ -115,7 +115,7 @@ new_fluid_str_setting(const char* value, const char* def, int hints, fluid_str_u static void delete_fluid_str_setting(fluid_setting_node_t* node) { - if (!node) return; + fluid_return_if_fail(node != NULL); FLUID_ASSERT(node->type, FLUID_STR_TYPE); @@ -169,7 +169,7 @@ new_fluid_num_setting(double min, double max, double def, static void delete_fluid_num_setting(fluid_setting_node_t* node) { - if (!node) return; + fluid_return_if_fail(node != NULL); FLUID_ASSERT (node->type, FLUID_NUM_TYPE); FLUID_FREE(node); @@ -206,7 +206,7 @@ new_fluid_int_setting(int min, int max, int def, static void delete_fluid_int_setting(fluid_setting_node_t* node) { - if (!node) return; + fluid_return_if_fail(node != NULL); FLUID_ASSERT (node->type, FLUID_INT_TYPE); FLUID_FREE(node); @@ -244,12 +244,11 @@ new_fluid_set_setting(void) static void delete_fluid_set_setting(fluid_setting_node_t* node) { - if (node) - { + fluid_return_if_fail(node != NULL); + FLUID_ASSERT (node->type, FLUID_SET_TYPE); delete_fluid_hashtable(node->set.hashtable); FLUID_FREE(node); - } } /** diff --git a/src/utils/fluid_sys.c b/src/utils/fluid_sys.c index f308de2b..f25870a0 100644 --- a/src/utils/fluid_sys.c +++ b/src/utils/fluid_sys.c @@ -741,10 +741,15 @@ new_fluid_timer (int msec, fluid_timer_callback_t callback, void* data, return timer; } -int +void delete_fluid_timer (fluid_timer_t *timer) { - int auto_destroy = timer->auto_destroy; + int auto_destroy; + + if(timer == NULL) + return; + + auto_destroy = timer->auto_destroy; timer->cont = 0; fluid_timer_join (timer); @@ -752,8 +757,6 @@ delete_fluid_timer (fluid_timer_t *timer) /* Shouldn't access timer now if auto_destroy enabled, since it has been destroyed */ if (!auto_destroy) FLUID_FREE (timer); - - return FLUID_OK; } int @@ -1087,8 +1090,11 @@ new_fluid_server_socket(int port, fluid_server_func_t func, void* data) return server_socket; } -int delete_fluid_server_socket(fluid_server_socket_t* server_socket) +void delete_fluid_server_socket(fluid_server_socket_t* server_socket) { + if(server_socket == NULL) + return; + server_socket->cont = 0; if (server_socket->socket != INVALID_SOCKET) { fluid_socket_close(server_socket->socket); @@ -1097,7 +1103,6 @@ int delete_fluid_server_socket(fluid_server_socket_t* server_socket) delete_fluid_thread(server_socket->thread); } FLUID_FREE(server_socket); - return FLUID_OK; } @@ -1279,8 +1284,11 @@ new_fluid_server_socket(int port, fluid_server_func_t func, void* data) return server_socket; } -int delete_fluid_server_socket(fluid_server_socket_t *server_socket) +void delete_fluid_server_socket(fluid_server_socket_t *server_socket) { + if(server_socket == NULL) + return; + server_socket->cont = 0; if (server_socket->socket != INVALID_SOCKET) @@ -1292,8 +1300,6 @@ int delete_fluid_server_socket(fluid_server_socket_t *server_socket) FLUID_FREE (server_socket); WSACleanup (); // Should be called the same number of times as WSAStartup - - return FLUID_OK; } #endif diff --git a/src/utils/fluid_sys.h b/src/utils/fluid_sys.h index 6e58ae69..908c28ad 100644 --- a/src/utils/fluid_sys.h +++ b/src/utils/fluid_sys.h @@ -102,7 +102,7 @@ fluid_timer_t* new_fluid_timer(int msec, fluid_timer_callback_t callback, void* data, int new_thread, int auto_destroy, int high_priority); -int delete_fluid_timer(fluid_timer_t* timer); +void delete_fluid_timer(fluid_timer_t* timer); int fluid_timer_join(fluid_timer_t* timer); int fluid_timer_stop(fluid_timer_t* timer); @@ -322,7 +322,7 @@ int fluid_ostream_printf (fluid_ostream_t out, char* format, ...); typedef int (*fluid_server_func_t)(void* data, fluid_socket_t client_socket, char* addr); fluid_server_socket_t* new_fluid_server_socket(int port, fluid_server_func_t func, void* data); -int delete_fluid_server_socket(fluid_server_socket_t* sock); +void delete_fluid_server_socket(fluid_server_socket_t* sock); int fluid_server_socket_join(fluid_server_socket_t* sock); void fluid_socket_close(fluid_socket_t sock); fluid_istream_t fluid_socket_get_istream(fluid_socket_t sock);