[graph-gtk] graph-gtk: fix memory leaks
- From: Clayton Walker <claytonw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [graph-gtk] graph-gtk: fix memory leaks
- Date: Sun, 20 Oct 2013 07:41:56 +0000 (UTC)
commit 53ab16d635e5180e5774e9cbd2ed51773f1a1e5b
Author: Clayton Walker <clayton m walker gmail com>
Date: Sun Oct 20 01:40:52 2013 -0600
graph-gtk: fix memory leaks
graph-gtk/graph-gtk-node.c | 36 ++++++++++++++++++++++---------
graph-gtk/graph-gtk-view.c | 50 +++++++++++++++++++++++++++++++++++--------
2 files changed, 65 insertions(+), 21 deletions(-)
---
diff --git a/graph-gtk/graph-gtk-node.c b/graph-gtk/graph-gtk-node.c
index f304e62..bc89cc2 100644
--- a/graph-gtk/graph-gtk-node.c
+++ b/graph-gtk/graph-gtk-node.c
@@ -175,7 +175,7 @@ graph_gtk_node_render_default(GraphGtkNode* self, cairo_t* cr)
//cairo_rectangle(cr, (self->x+self->offset_x)-10, (self->y+self->offset_y)-10,
(self->x+self->offset_x)+20, (self->y+self->offset_y)+20);
cairo_paint(cr);
- cairo_surface_finish(shadow);
+ cairo_surface_destroy (shadow);
cairo_destroy(shadow_context);
}
@@ -237,7 +237,7 @@ graph_gtk_node_render_default(GraphGtkNode* self, cairo_t* cr)
M_PI, -M_PI/2.0);
cairo_close_path(cr); //probably unecessary
- cairo_pattern_t *gradient = cairo_pattern_create_linear(0, -15, 0, 25);
+ cairo_pattern_t *gradient = cairo_pattern_create_linear (0, -15, 0, 25);
if(!self->is_selected)
{
@@ -254,22 +254,28 @@ graph_gtk_node_render_default(GraphGtkNode* self, cairo_t* cr)
cairo_set_line_width(cr, 0.5);
cairo_stroke(cr);
+ cairo_pattern_destroy (gradient);
+
cairo_select_font_face (cr, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, 14);
cairo_set_source_rgb(cr, 200.0/256.0, 200.0/256.0, 200.0/256.0);
cairo_move_to(cr, (self->x+self->offset_x)+4, (self->y+self->offset_y)+13);
cairo_show_text(cr, self->name);
- GList *pad;
- for(pad = graph_gtk_node_get_input_pads(self); pad != NULL; pad = pad->next)
+ GList *pad, *ref;
+ ref = graph_gtk_node_get_input_pads (self);
+ for(pad = ref; pad != NULL; pad = pad->next)
{
graph_gtk_pad_render((GraphGtkPad*)pad->data, cr);
}
+ g_list_free (ref);
- for(pad = graph_gtk_node_get_output_pads(self); pad != NULL; pad = pad->next)
+ ref = graph_gtk_node_get_output_pads(self);
+ for(pad = ref; pad != NULL; pad = pad->next)
{
graph_gtk_pad_render((GraphGtkPad*)pad->data, cr);
}
+ g_list_free (ref);
if(self->show_image && self->image)
{
@@ -356,8 +362,9 @@ graph_gtk_node_connect_to(GraphGtkNode* source, const gchar* output_pad, GraphGt
{
GraphGtkPad *source_pad = NULL, *sink_pad = NULL;
- GList* list;
- for(list = graph_gtk_node_get_pads(source); list != NULL; list = list->next)
+ GList *list, *ref;
+ ref = graph_gtk_node_get_pads (source);
+ for(list = ref; list != NULL; list = list->next)
{
GraphGtkPad *pad = (GraphGtkPad*)list->data;
if(0 == g_strcmp0(pad->name, output_pad))
@@ -366,8 +373,10 @@ graph_gtk_node_connect_to(GraphGtkNode* source, const gchar* output_pad, GraphGt
break;
}
}
+ g_list_free (ref);
- for(list = graph_gtk_node_get_pads(sink); list != NULL; list = list->next)
+ ref = graph_gtk_node_get_pads (sink);
+ for(list = ref; list != NULL; list = list->next)
{
GraphGtkPad *pad = (GraphGtkPad*)list->data;
if(0 == g_strcmp0(pad->name, input_pad))
@@ -376,6 +385,7 @@ graph_gtk_node_connect_to(GraphGtkNode* source, const gchar* output_pad, GraphGt
break;
}
}
+ g_list_free (ref);
if(!source_pad || !sink_pad)
return;
@@ -552,24 +562,28 @@ graph_gtk_node_is_within(GraphGtkNode* self, int x, int y)
GraphGtkPad*
graph_gtk_node_is_on_pad(GraphGtkNode* self, int x, int y)
{
- GList *list;
int px, py;
- for(list = graph_gtk_node_get_input_pads(self); list != NULL; list = list->next)
+ GList *list, *ref;
+ ref = graph_gtk_node_get_input_pads (self);
+ for(list = ref; list != NULL; list = list->next)
{
GraphGtkPad *pad = (GraphGtkPad*)list->data;
graph_gtk_pad_get_position(pad, &px, &py);
if(x > px-5 && x < px+5 && y > py-5 && y < py+5)
return pad;
}
+ g_list_free (ref);
- for(list = graph_gtk_node_get_output_pads(self); list != NULL; list = list->next)
+ ref = graph_gtk_node_get_output_pads (self);
+ for(list = ref; list != NULL; list = list->next)
{
GraphGtkPad *pad = (GraphGtkPad*)list->data;
graph_gtk_pad_get_position(pad, &px, &py);
if(x > px-5 && x < px+5 && y > py-5 && y < py+5)
return pad;
}
+ g_list_free (ref);
return NULL;
}
diff --git a/graph-gtk/graph-gtk-view.c b/graph-gtk/graph-gtk-view.c
index 6a6ba29..efe52d5 100644
--- a/graph-gtk/graph-gtk-view.c
+++ b/graph-gtk/graph-gtk-view.c
@@ -181,6 +181,7 @@ graph_gtk_view_draw(GtkWidget *widget, cairo_t* cr)
{
GraphGtkView *view = GRAPH_GTK_VIEW(widget);
+ // view background
cairo_set_source_rgb(cr, 124.0/256.0, 124.0/256.0, 124.0/256.0);
cairo_paint(cr);
@@ -221,7 +222,8 @@ graph_gtk_view_draw(GtkWidget *widget, cairo_t* cr)
{
GraphGtkNode *node = (GraphGtkNode*)nodes->data;
- GList *pads;
+ GList *pads, *ref;
+ /*
for(pads = graph_gtk_node_get_input_pads(node); pads != NULL; pads = pads->next)
{
GraphGtkPad *pad = (GraphGtkPad*)pads->data;
@@ -232,8 +234,9 @@ graph_gtk_view_draw(GtkWidget *widget, cairo_t* cr)
graph_gtk_connection_render(connection, cr);
}
}
-
- for(pads = graph_gtk_node_get_output_pads(node); pads != NULL; pads = pads->next)
+ */
+ ref = graph_gtk_node_get_output_pads (node);
+ for(pads = ref; pads != NULL; pads = pads->next)
{
GraphGtkPad *pad = (GraphGtkPad*)pads->data;
GList *connections;
@@ -243,6 +246,7 @@ graph_gtk_view_draw(GtkWidget *widget, cairo_t* cr)
graph_gtk_connection_render(connection, cr);
}
}
+ g_list_free (ref);
}
GList* list;
@@ -263,6 +267,28 @@ graph_gtk_view_draw(GtkWidget *widget, cairo_t* cr)
cairo_set_source_rgb(cr, 0.0, 1, 0.0);
cairo_set_line_width(cr, 0.5);
cairo_stroke(cr);
+
+ // FIXME: Factor this out
+ int from_x, from_y, to_x, to_y;
+ from_x = x;
+ from_y = y;
+ to_x = view->mouse_x + view->pan_x;
+ to_y = view->mouse_y + view->pan_y;
+
+ cairo_set_line_width(cr, 1);
+ cairo_set_source_rgb(cr, 0, 0, 0);
+
+ cairo_move_to(cr, from_x, from_y);
+
+ gdouble offset =
+ ((to_x > from_x) ? ((to_x-from_x)/2) : ((from_x-to_x)/2))
+ + ABS(from_y-to_y)/6;
+
+ cairo_curve_to(cr, from_x+offset, from_y,
+ to_x-offset, to_y,
+ to_x, to_y);
+
+ cairo_stroke(cr);
}
return FALSE;
@@ -514,20 +540,24 @@ graph_gtk_view_remove_node(GraphGtkView* self, GraphGtkNode* node)
{
self->nodes = g_list_remove(self->nodes, node);
- GList *pad;
- for(pad = graph_gtk_node_get_input_pads(node); pad != NULL; pad = pad->next)
+ GList *pad, *ref;
+ ref = graph_gtk_node_get_input_pads (node);
+ for(pad = ref; pad != NULL; pad = pad->next)
{
- graph_gtk_pad_disconnect((GraphGtkPad*)(pad->data));
+ graph_gtk_pad_disconnect ((GraphGtkPad*) (pad->data));
}
+ g_list_free (ref);
- for(pad = graph_gtk_node_get_output_pads(node); pad != NULL; pad = pad->next)
+ ref = graph_gtk_node_get_output_pads (node);
+ for(pad = ref; pad != NULL; pad = pad->next)
{
- graph_gtk_pad_disconnect((GraphGtkPad*)(pad->data));
+ graph_gtk_pad_disconnect ((GraphGtkPad*) (pad->data));
}
+ g_list_free (ref);
- g_object_unref(G_OBJECT(node));
+ g_object_unref (G_OBJECT (node));
- REDRAW();
+ REDRAW ();
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]