From: Christophe CURIS <[email protected]> A number of configuration options are useful only during the startup, so it is possible to free them when ready.
Signed-off-by: Christophe CURIS <[email protected]> --- wmix/config.c | 38 ++++++++++++++++++++++++++++++++++++++ wmix/include/config.h | 3 +++ wmix/wmix.c | 6 +++--- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/wmix/config.c b/wmix/config.c index f335df9..ee0a024 100644 --- a/wmix/config.c +++ b/wmix/config.c @@ -45,6 +45,9 @@ /* The global configuration */ struct _Config config; +/* The default device used for Mixer control */ +static const char default_mixer_device[] = "/dev/mixer"; + /* Default color for OSD */ const char default_osd_color[] = "green"; @@ -56,6 +59,7 @@ void config_init(void) { memset(&config, 0, sizeof(config)); + config.mixer_device = (char *) default_mixer_device; config.mousewheel = 1; config.scrolltext = 1; config.wheel_button_up = 4; @@ -66,6 +70,36 @@ void config_init(void) } /* + * Release memory associated with configuration + * + * This does not concern the complete configuration, only the parameters + * that are needed during startup but are not useful during run-time + */ +void config_release(void) +{ + int i; + + if (config.file) + free(config.file); + + if (config.display_name) + free(config.display_name); + + if (config.mixer_device != default_mixer_device) + free(config.mixer_device); + + if (config.osd_color != default_osd_color) + free(config.osd_color); + + for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { + if (config.exclude_channel[i]) + free(config.exclude_channel[i]); + else + break; + } +} + +/* * Parse Command-Line options * * Supposed to be called before reading config file, as there's an @@ -97,6 +131,8 @@ void parse_cli_options(int argc, char **argv) break; case 'd': + if (config.display_name) + free(config.display_name); config.display_name = strdup(optarg); break; @@ -120,6 +156,8 @@ void parse_cli_options(int argc, char **argv) break; case 'm': + if (config.mixer_device != default_mixer_device) + free(config.mixer_device); config.mixer_device = strdup(optarg); break; diff --git a/wmix/include/config.h b/wmix/include/config.h index 602d400..702a382 100644 --- a/wmix/include/config.h +++ b/wmix/include/config.h @@ -53,6 +53,9 @@ extern const char default_osd_color[]; /* Sets the default values in the config */ void config_init(void); +/* Release memory associated with configuration (this concern only stuff needed during startup) */ +void config_release(void); + /* Sets configuration from command line */ void parse_cli_options(int argc, char **argv); diff --git a/wmix/wmix.c b/wmix/wmix.c index e8cb6c6..1f7ddab 100644 --- a/wmix/wmix.c +++ b/wmix/wmix.c @@ -66,9 +66,6 @@ int main(int argc, char **argv) parse_cli_options(argc, argv); config_read(); - if (config.mixer_device == NULL) - config.mixer_device = "/dev/mixer"; - mixer_init(config.mixer_device, config.verbose, (const char **)config.exclude_channel); mixer_set_channel(0); @@ -94,6 +91,9 @@ int main(int argc, char **argv) dockapp_init(display); new_window("wmix", 64, 64); new_osd(DisplayWidth(display, DefaultScreen(display)) - 200, 60); + + config_release(); + blit_string("wmix 3.0"); scroll_text(3, 4, 57, true); ui_update(); -- 1.9.2 -- To unsubscribe, send mail to [email protected].
