[Goodies-commits] r1920 - in xfce4-cpufreq-plugin/trunk: . panel-plugin
Thomas Schreck
shrek at xfce.org
Thu Aug 24 17:35:28 CEST 2006
Author: shrek
Date: 2006-08-24 15:35:26 +0000 (Thu, 24 Aug 2006)
New Revision: 1920
Modified:
xfce4-cpufreq-plugin/trunk/ChangeLog
xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-linux.c
xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-overview.c
xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-plugin.c
xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-utils.c
Log:
* Fix mem leak and bug with more cpus
Modified: xfce4-cpufreq-plugin/trunk/ChangeLog
===================================================================
--- xfce4-cpufreq-plugin/trunk/ChangeLog 2006-08-23 22:07:33 UTC (rev 1919)
+++ xfce4-cpufreq-plugin/trunk/ChangeLog 2006-08-24 15:35:26 UTC (rev 1920)
@@ -1,3 +1,7 @@
+2006-08-24 17:36 Thomas Schreck <shrek at xfce.org>
+
+ * Fix mem leak and bug with more cpus
+
2006-08-23 22:48 Thomas Schreck <shrek at xfce.org>
* rewrote most of the code
Modified: xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-linux.c
===================================================================
--- xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-linux.c 2006-08-23 22:07:33 UTC (rev 1919)
+++ xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-linux.c 2006-08-24 15:35:26 UTC (rev 1920)
@@ -47,7 +47,7 @@
{
gint i = 0;
- fileContent = (gchar*)malloc (sizeof(gchar) * 255);
+ fileContent = g_new (gchar, 255);
fgets (fileContent, 255, file);
fclose (file);
@@ -77,7 +77,7 @@
{
gint i = 0;
- fileContent = (gchar*)malloc (sizeof(gchar) * 255);
+ fileContent = g_new (gchar, 255);
fgets (fileContent, 255, file);
fclose (file);
@@ -105,7 +105,7 @@
file = fopen (filePath, "r");
if (file)
{
- cpu->scaling_driver = (gchar*)malloc (sizeof (gchar) * 15);
+ cpu->scaling_driver = g_new (gchar, 15);
fscanf (file, "%s", cpu->scaling_driver);
fclose (file);
}
@@ -134,7 +134,7 @@
file = fopen (filePath, "r");
if (file)
{
- cpu->cur_governor = (gchar*)malloc (sizeof (gchar) * 15);
+ cpu->cur_governor = g_new (gchar, 15);
fscanf (file, "%d", cpu->cur_governor);
fclose (file);
}
@@ -239,7 +239,7 @@
for (j = 0; j < i; j++)
{
- return cpufreq_cpu_parse_sysfs_init (j);
+ cpufreq_cpu_parse_sysfs_init (j);
}
return TRUE;
@@ -254,8 +254,8 @@
// TODO check if freq is different
- cpu_freq = (gchar*)malloc (sizeof (gchar) * 30);
- cpu_num = (gchar*)malloc (sizeof (gchar) * 3);
+ cpu_freq = g_new (gchar, 30);
+ cpu_num = g_new (gchar, 3);
sprintf (cpu_num, "%d", cpu_number);
sprintf (cpu_freq, "%d", freq);
cmd = g_strconcat ("/bin/echo ",
@@ -300,7 +300,7 @@
if (governor == NULL) //TODO && governor in list
return FALSE;
- cpu_num = (gchar*)malloc (sizeof (gchar) * 3);
+ cpu_num = g_new (gchar, 3);
sprintf (cpu_num, "%d", cpu_number);
cmd = g_strconcat ("/bin/echo ",
governor,
Modified: xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-overview.c
===================================================================
--- xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-overview.c 2006-08-23 22:07:33 UTC (rev 1919)
+++ xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-overview.c 2006-08-24 15:35:26 UTC (rev 1920)
@@ -43,14 +43,20 @@
if (g_ascii_strcasecmp (cpu->cur_governor, "userspace") != 0)
{
xfce_warn ("You could only change CPU frequency, if you use the \"userspace\" governor");
+ g_free (new_freq);
return;
}
if (xfce_confirm (_("Are you sure to change the frequency !"), GTK_STOCK_YES, NULL) == FALSE)
+ {
+ g_free (new_freq);
return;
+ }
if (cpufreq_cpu_set_freq (cpu_number, freq) == FALSE)
xfce_err (_("It was not possible to change the frequency"));
+
+ g_free (new_freq);
}
static void
@@ -61,10 +67,15 @@
new_governor = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
if (xfce_confirm (_("Are you sure to change the governor !"), GTK_STOCK_YES, NULL) == FALSE)
+ {
+ g_free (new_governor);
return;
+ }
if (cpufreq_cpu_set_governor (cpu_number, new_governor) == FALSE)
xfce_err (_("It was not possible to change the governor"));
+
+ g_free (new_governor);
}
static void
Modified: xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-plugin.c
===================================================================
--- xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-plugin.c 2006-08-23 22:07:33 UTC (rev 1919)
+++ xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-plugin.c 2006-08-24 15:35:26 UTC (rev 1920)
@@ -47,8 +47,11 @@
label = g_strconcat (small ? "<span size=\"xx-small\">" : "<span size=\"x-small\">",
cpuFreq->options->show_label_freq ? freq : "",
+
cpuFreq->options->show_label_freq && cpuFreq->options->show_label_governor ? "\n" : "",
+
cpuFreq->options->show_label_governor ? cpu->cur_governor : "",
+
"</span>",
NULL);
@@ -66,11 +69,13 @@
freq = cpufreq_get_human_readable_freq (cpu->cur_freq);
if (cpuFreq->options->show_label_governor && cpuFreq->options->show_label_freq)
- tooltip_msg = g_strdup_printf (_("CPU Frequency Plugin"));
+ tooltip_msg = g_strdup_printf (_("%d cpu available"), cpuFreq->cpus->len);
else
tooltip_msg = g_strconcat (!cpuFreq->options->show_label_freq ? _("Frequency: ") : "",
!cpuFreq->options->show_label_freq ? freq : "",
+
!cpuFreq->options->show_label_freq && !cpuFreq->options->show_label_governor ? "\n" : "",
+
!cpuFreq->options->show_label_governor ? _("Governor: ") : "",
!cpuFreq->options->show_label_governor ? cpu->cur_governor : "",
NULL);
@@ -83,46 +88,6 @@
}
gboolean
-cpufreq_update_icon (CpuInfo *cpu)
-{
- gchar *cpu_icon_name;
- guint psize, isize;
- GdkPixbuf *pixbuf = NULL;
-
- if (!cpuFreq->options->show_icon)
- return TRUE;
-
- if (cpu->cur_freq == cpu->max_freq)
- cpu_icon_name = g_strdup ("cpu");
- else
- {
- if (cpu->cur_freq == cpu->min_freq)
- cpu_icon_name = g_strdup ("cpu");
- else
- cpu_icon_name = g_strdup ("cpu");
- }
-
- psize = xfce_panel_plugin_get_size (cpuFreq->plugin);
- isize = psize - (2 * BORDER) -
- (2 * (psize > 26 ? 2 : 0)) -
- (2 * MAX (cpuFreq->frame->style->xthickness, cpuFreq->frame->style->ythickness));
-
- pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), cpu_icon_name, isize , 0, NULL);
-
- if (pixbuf)
- {
- gtk_image_set_from_pixbuf (GTK_IMAGE (cpuFreq->icon), pixbuf);
- g_object_unref (G_OBJECT (pixbuf));
- }
- else
- return FALSE;
-
- g_free (cpu_icon_name);
-
- return TRUE;
-}
-
-gboolean
cpufreq_update_plugin (void)
{
gint i;
@@ -133,8 +98,6 @@
return FALSE;
if (cpufreq_update_tooltip (cpu) == FALSE)
return FALSE;
- if (cpufreq_update_icon (cpu) == FALSE)
- return FALSE;
}
return TRUE;
}
@@ -143,17 +106,13 @@
cpufreq_restart_timeout (void)
{
g_source_remove (cpuFreq->timeoutHandle);
- cpuFreq->timeoutHandle = g_timeout_add (
- 100,
- (GSourceFunc) cpufreq_update_cpus,
- NULL);
+ cpuFreq->timeoutHandle = g_timeout_add (100, (GSourceFunc)cpufreq_update_cpus, NULL);
}
gboolean
cpufreq_widgets (void)
{
gint size;
- gchar *tooltip_msg;
GtkWidget *box;
GtkOrientation orientation;
@@ -177,8 +136,7 @@
gtk_container_set_border_width (GTK_CONTAINER (box), BORDER);
gtk_container_add (GTK_CONTAINER (cpuFreq->frame), box);
- tooltip_msg = _("CPU Frequency Plugin");
- gtk_tooltips_set_tip (cpuFreq->tooltip, cpuFreq->ebox, tooltip_msg, NULL);
+ gtk_tooltips_set_tip (cpuFreq->tooltip, cpuFreq->ebox, "", NULL);
if(cpuFreq->options->show_icon)
{
@@ -265,8 +223,6 @@
g_free (cpu);
}
- gksu_context_free (cpuFreq->gksu_ctx);
-
gtk_tooltips_set_tip (cpuFreq->tooltip, cpuFreq->ebox, NULL, NULL);
g_object_unref (cpuFreq->tooltip);
@@ -278,8 +234,7 @@
static gboolean
cpufreq_set_size (XfcePanelPlugin *plugin, gint wsize)
{
- if (xfce_panel_plugin_get_orientation (plugin) ==
- GTK_ORIENTATION_HORIZONTAL)
+ if (xfce_panel_plugin_get_orientation (plugin) == GTK_ORIENTATION_HORIZONTAL)
gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, wsize);
else
gtk_widget_set_size_request (GTK_WIDGET (plugin), wsize, -1);
@@ -288,8 +243,7 @@
}
static void
-cpufreq_orientation_changed (XfcePanelPlugin *plugin,
- GtkOrientation orientation)
+cpufreq_orientation_changed (XfcePanelPlugin *plugin, GtkOrientation orientation)
{
if (cpufreq_widgets () == FALSE)
xfce_err (_("Could not create widgets !"));
Modified: xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-utils.c
===================================================================
--- xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-utils.c 2006-08-23 22:07:33 UTC (rev 1919)
+++ xfce4-cpufreq-plugin/trunk/panel-plugin/xfce4-cpufreq-utils.c 2006-08-24 15:35:26 UTC (rev 1920)
@@ -28,7 +28,7 @@
cpufreq_get_human_readable_freq (guint freq)
{
guint div;
- gchar *freq_unit;
+ gchar *readable_freq, *freq_unit;
if (freq > 999999)
{
@@ -42,9 +42,12 @@
}
if ((freq % div) == 0 || div == 1000)
- return g_strdup_printf ("%d %s", (freq/div), freq_unit);
+ readable_freq = g_strdup_printf ("%d %s", (freq/div), freq_unit);
else
- return g_strdup_printf ("%3.2f %s", ((gfloat)freq/div), freq_unit);
+ readable_freq = g_strdup_printf ("%3.2f %s", ((gfloat)freq/div), freq_unit);
+
+ g_free (freq_unit);
+ return readable_freq;
}
guint
More information about the Goodies-commits
mailing list