wmix: release memory for startup-only configuration stuff after startup

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 <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS 2014-06-07 21:21:52 +02:00 committed by Carlos R. Mafra
parent b1fcdb1552
commit d7add56750
3 changed files with 44 additions and 3 deletions

View file

@ -45,6 +45,9 @@
/* The global configuration */ /* The global configuration */
struct _Config config; struct _Config config;
/* The default device used for Mixer control */
static const char default_mixer_device[] = "/dev/mixer";
/* Default color for OSD */ /* Default color for OSD */
const char default_osd_color[] = "green"; const char default_osd_color[] = "green";
@ -56,6 +59,7 @@ void config_init(void)
{ {
memset(&config, 0, sizeof(config)); memset(&config, 0, sizeof(config));
config.mixer_device = (char *) default_mixer_device;
config.mousewheel = 1; config.mousewheel = 1;
config.scrolltext = 1; config.scrolltext = 1;
config.wheel_button_up = 4; config.wheel_button_up = 4;
@ -65,6 +69,36 @@ void config_init(void)
config.osd_color = (char *) default_osd_color; config.osd_color = (char *) default_osd_color;
} }
/*
* 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 * Parse Command-Line options
* *
@ -97,6 +131,8 @@ void parse_cli_options(int argc, char **argv)
break; break;
case 'd': case 'd':
if (config.display_name)
free(config.display_name);
config.display_name = strdup(optarg); config.display_name = strdup(optarg);
break; break;
@ -120,6 +156,8 @@ void parse_cli_options(int argc, char **argv)
break; break;
case 'm': case 'm':
if (config.mixer_device != default_mixer_device)
free(config.mixer_device);
config.mixer_device = strdup(optarg); config.mixer_device = strdup(optarg);
break; break;

View file

@ -53,6 +53,9 @@ extern const char default_osd_color[];
/* Sets the default values in the config */ /* Sets the default values in the config */
void config_init(void); 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 */ /* Sets configuration from command line */
void parse_cli_options(int argc, char **argv); void parse_cli_options(int argc, char **argv);

View file

@ -66,9 +66,6 @@ int main(int argc, char **argv)
parse_cli_options(argc, argv); parse_cli_options(argc, argv);
config_read(); 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_init(config.mixer_device, config.verbose, (const char **)config.exclude_channel);
mixer_set_channel(0); mixer_set_channel(0);
@ -94,6 +91,9 @@ int main(int argc, char **argv)
dockapp_init(display); dockapp_init(display);
new_window("wmix", 64, 64); new_window("wmix", 64, 64);
new_osd(DisplayWidth(display, DefaultScreen(display)) - 200, 60); new_osd(DisplayWidth(display, DefaultScreen(display)) - 200, 60);
config_release();
blit_string("wmix 3.0"); blit_string("wmix 3.0");
scroll_text(3, 4, 57, true); scroll_text(3, 4, 57, true);
ui_update(); ui_update();