Skip to content

Commit

Permalink
Fix several memory leaks
Browse files Browse the repository at this point in the history
After about four days of continuous run, Multiload-ng in my system
uses over 800M memory. After running under Valgrind, many memory
leaks were identified and fixed. Some of them were little leaks (some
hundred bytes), other were more serious. Upgrade is recommended.
  • Loading branch information
udda committed Dec 5, 2016
1 parent 002377f commit 156b5c0
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 20 deletions.
2 changes: 2 additions & 0 deletions common/graph-parm.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ multiload_graph_parm_get_data (int Maximum, int data[4], LoadGraph *g, Parametri
}

}
g_free (stdout);
g_free (stderr);

if (xd->error == TRUE) {
memset(xd->result, 0, 4*sizeof(xd->result[0]));
Expand Down
3 changes: 2 additions & 1 deletion common/load-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ load_graph_cairo_set_gradient(cairo_t *cr, double width, double height, int dire
cairo_pattern_add_color_stop_rgb (pat, 0, a->red, a->green, a->blue);
cairo_pattern_add_color_stop_rgb (pat, 1, b->red, b->green, b->blue);
cairo_set_source(cr, pat);
cairo_pattern_destroy (pat);
}

/* Redraws the backing pixmap for the load graph and updates the window */
Expand Down Expand Up @@ -446,7 +447,7 @@ load_graph_new (MultiloadPlugin *ma, guint id)
g_signal_connect (G_OBJECT(g->disp), "draw", G_CALLBACK (load_graph_draw_cb), g);
#endif */
g_signal_connect (G_OBJECT(g->disp), "configure_event", G_CALLBACK (load_graph_configure), g);
g_signal_connect (G_OBJECT(g->disp), "destroy", G_CALLBACK (load_graph_destroy), g);
g_signal_connect (G_OBJECT(g->main_widget), "destroy", G_CALLBACK (load_graph_destroy), g);
g_signal_connect (G_OBJECT(g->disp), "button-press-event", G_CALLBACK (load_graph_clicked), g);
g_signal_connect (G_OBJECT(g->disp), "enter-notify-event", G_CALLBACK(load_graph_mouse_move_cb), g);
g_signal_connect (G_OBJECT(g->disp), "leave-notify-event", G_CALLBACK(load_graph_mouse_move_cb), g);
Expand Down
14 changes: 8 additions & 6 deletions common/multiload.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,20 +366,22 @@ multiload_new()
}

void
multiload_destroy(MultiloadPlugin *ma)
multiload_free(MultiloadPlugin *ma)
{
gint i;

for (i = 0; i < GRAPH_MAX; i++) {
load_graph_stop(ma->graphs[i]);
gtk_widget_destroy(ma->graphs[i]->main_widget);
load_graph_stop (ma->graphs[i]);
gtk_widget_destroy (ma->graphs[i]->main_widget);

load_graph_unalloc(ma->graphs[i]);
g_free(ma->graphs[i]);
load_graph_unalloc (ma->graphs[i]);
g_free (ma->graphs[i]);

g_free(ma->extra_data[i]);
g_free (ma->extra_data[i]);
}

g_free (ma);

g_debug("[multiload] Destroyed");
}

Expand Down
2 changes: 1 addition & 1 deletion common/multiload.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ multiload_defaults(MultiloadPlugin *ma);
G_GNUC_INTERNAL MultiloadPlugin*
multiload_new();
G_GNUC_INTERNAL void
multiload_destroy(MultiloadPlugin *ma);
multiload_free(MultiloadPlugin *ma);
G_GNUC_INTERNAL int
multiload_find_graph_by_name(char *str, char **suffix);

Expand Down
1 change: 1 addition & 0 deletions common/ps-settings-impl-gkeyfile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ multiload_ps_settings_open_for_read(MultiloadPlugin *ma)
}
}

g_free(fname);
g_clear_error(&err);
return gkf;
}
Expand Down
3 changes: 3 additions & 0 deletions common/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,12 @@ multiload_ui_parse_cmdline(int *argc, char ***argv, GOptionEntry *extra_entries)

if (!g_option_context_parse (context, argc, argv, &error)) {
g_print ("%s\n", error->message);
g_error_free (error);
exit (1);
}

g_option_context_free (context);

return options;
}

Expand Down
14 changes: 7 additions & 7 deletions indicator/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ indicator_cleanup(int sig)
sprintf(signame, "Signal %d", sig);

printf("Received %s, cleaning up...\n", signame);
remove(icon_filename[0]);
remove(icon_filename[1]);
remove(icon_directory);
remove(icon_filename[0]);
remove(icon_filename[1]);
remove(icon_directory);

exit(0);
exit(0);
}

static void
indicator_destroy_cb(GtkWidget *widget, MultiloadPlugin *ma)
{
gtk_main_quit ();
g_free(ma);
indicator_cleanup(0);
gtk_main_quit ();
multiload_free (ma);
indicator_cleanup (0);
}

static void
Expand Down
4 changes: 2 additions & 2 deletions standalone/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
static void
standalone_destroy_cb (GtkWidget *widget, MultiloadPlugin *multiload)
{
gtk_main_quit ();
g_free(multiload);
gtk_main_quit ();
multiload_free (multiload);
}

static void
Expand Down
4 changes: 2 additions & 2 deletions systray/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ static guint timer_indexes[GRAPH_MAX];
static void
systray_destroy_cb(GtkWidget *widget, MultiloadPlugin *ma)
{
gtk_main_quit ();
g_free(ma);
gtk_main_quit ();
multiload_free (ma);
}

static void
Expand Down
2 changes: 1 addition & 1 deletion xfce4/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ xfce_free_cb (XfcePanelPlugin *plugin, MultiloadPlugin *multiload)
if (G_UNLIKELY (multiload->pref_dialog != NULL))
gtk_widget_destroy (multiload->pref_dialog);

multiload_destroy (multiload);
multiload_free (multiload);
gtk_widget_destroy (GTK_WIDGET(multiload->container));

g_slice_free (MultiloadPlugin, multiload);
Expand Down

0 comments on commit 156b5c0

Please sign in to comment.