[Pkg-wmaker-commits] [wmix] 24/44: wmix: release memory for startup-only configuration stuff after startup

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Sep 29 10:40:13 UTC 2017


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch upstream
in repository wmix.

commit 183fabf0620bec0d31d7dfcb67f7f33cf243f23a
Author: Christophe CURIS <christophe.curis at free.fr>
Date:   Sat Jun 7 21:21:52 2014 +0200

    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 at free.fr>
---
 config.c         | 38 ++++++++++++++++++++++++++++++++++++++
 include/config.h |  3 +++
 wmix.c           |  6 +++---
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/config.c b/config.c
index f335df9..ee0a024 100644
--- a/config.c
+++ b/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/include/config.h b/include/config.h
index 602d400..702a382 100644
--- a/include/config.h
+++ b/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.c b/wmix.c
index e8cb6c6..1f7ddab 100644
--- a/wmix.c
+++ b/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();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmix.git



More information about the Pkg-wmaker-commits mailing list