[Xfce4-commits] <xfce4-cpufreq-plugin:master> Add new cpuinfo_free to deal with memory leaks.
Harald Judt
noreply at xfce.org
Sun Aug 18 11:32:15 CEST 2013
Updating branch refs/heads/master
to e5b824087d347de8edd088834c09aa1c69cf953a (commit)
from 63cd36e4e3b97f8c3bd557a774084fc63de024f6 (commit)
commit e5b824087d347de8edd088834c09aa1c69cf953a
Author: Harald Judt <h.judt at gmx.at>
Date: Sun Aug 11 12:27:16 2013 +0200
Add new cpuinfo_free to deal with memory leaks.
Code for freeing CpuInfo memory is scattered all over the place, but
in many cases not all fields are freed, causing memory leaks.
Let's define a common function to clean up that mess a bit.
panel-plugin/xfce4-cpufreq-plugin.c | 15 +++++++++++----
panel-plugin/xfce4-cpufreq-plugin.h | 3 +++
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/panel-plugin/xfce4-cpufreq-plugin.c b/panel-plugin/xfce4-cpufreq-plugin.c
index dd3449e..ce7d7e5 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.c
+++ b/panel-plugin/xfce4-cpufreq-plugin.c
@@ -348,6 +348,16 @@ cpufreq_write_config (XfcePanelPlugin *plugin)
xfce_rc_close (rc);
}
+void
+cpuinfo_free (CpuInfo *cpu)
+{
+ g_free (cpu->cur_governor);
+ g_free (cpu->scaling_driver);
+ g_list_free (cpu->available_freqs);
+ g_list_free_full (cpu->available_governors, g_free);
+ g_free (cpu);
+}
+
static void
cpufreq_free (XfcePanelPlugin *plugin)
{
@@ -360,10 +370,7 @@ cpufreq_free (XfcePanelPlugin *plugin)
{
CpuInfo *cpu = g_ptr_array_index (cpuFreq->cpus, i);
g_ptr_array_remove_fast (cpuFreq->cpus, cpu);
- g_free (cpu->cur_governor);
- g_list_free (cpu->available_freqs);
- g_list_free (cpu->available_governors);
- g_free (cpu);
+ cpuinfo_free (cpu);
}
g_ptr_array_free (cpuFreq->cpus, TRUE);
diff --git a/panel-plugin/xfce4-cpufreq-plugin.h b/panel-plugin/xfce4-cpufreq-plugin.h
index f976cb9..890b22e 100644
--- a/panel-plugin/xfce4-cpufreq-plugin.h
+++ b/panel-plugin/xfce4-cpufreq-plugin.h
@@ -68,6 +68,9 @@ CpuFreqPlugin *cpuFreq;
G_BEGIN_DECLS
+void
+cpuinfo_free (CpuInfo *cpu);
+
gboolean
cpufreq_update_plugin (void);
More information about the Xfce4-commits
mailing list