From 3259ddd1e74e88642913c2b6facc1377ac875a9e Mon Sep 17 00:00:00 2001
From: David <dbphillipsnz@gmail.com>
Date: Fri, 4 Apr 2014 16:39:54 +1300
Subject: Segfault bugfix

---
 trayfreq.c                  |  2 ++
 trayfreq_set/trayfreq_set.c | 28 ++++++++++++++++++++--------
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/trayfreq.c b/trayfreq.c
index f8b0cc8..ec82705 100644
--- a/trayfreq.c
+++ b/trayfreq.c
@@ -39,6 +39,8 @@ void config_init()
 	gboolean home_config_exists;
 	config.key_file = NULL;
 
+	printf("Battery governor: %s",_DEFAULT_BAT_GOV);
+
 	config.file_name = g_strconcat(getenv("HOME"), "/.trayfreq.config", NULL);
 
 	// Check if ~/.trayfreq.config exists
diff --git a/trayfreq_set/trayfreq_set.c b/trayfreq_set/trayfreq_set.c
index 083d993..d90717a 100644
--- a/trayfreq_set/trayfreq_set.c
+++ b/trayfreq_set/trayfreq_set.c
@@ -29,8 +29,11 @@ void set_freq_max(char* freq, char* core)
 	sprintf(file_path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_max_freq", core);
 
 	FILE* fd = fopen(file_path, "w");
-	fprintf(fd, freq);
-	fclose(fd);
+	if (fd)
+	{
+		fprintf(fd, freq);
+		fclose(fd);
+	}
 }
 
 void set_freq_min(char* freq, char* core)
@@ -39,8 +42,11 @@ void set_freq_min(char* freq, char* core)
 	sprintf(file_path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_min_freq", core);
 
 	FILE* fd = fopen(file_path, "w");
-	fprintf(fd, freq);
-	fclose(fd);
+	if (fd)
+	{
+		fprintf(fd, freq);
+		fclose(fd);
+	}
 }
 
 static void set_speed(char* freq, char* core)
@@ -49,8 +55,11 @@ static void set_speed(char* freq, char* core)
 	sprintf(file_path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_setspeed", core);
 
 	FILE* fd = fopen(file_path, "w");
-	fprintf(fd, freq);
-	fclose(fd);
+	if (fd)
+	{
+		fprintf(fd, freq);
+		fclose(fd);
+	}
 }
 
 void set_gov(char* gov, char* core)
@@ -59,8 +68,11 @@ void set_gov(char* gov, char* core)
 	sprintf(file_path, "/sys/devices/system/cpu/cpu%s/cpufreq/scaling_governor", core);
 
 	FILE* fd = fopen(file_path, "w");
-	fprintf(fd, gov);
-	fclose(fd);
+	if (fd)
+	{
+		fprintf(fd, gov);
+		fclose(fd);
+	}
 }
 
 void set_freq(char* freq, char* core)
-- 
cgit v1.1