[dia] scan-build: fix various "bugs"



commit b24379377cfc5064d8ea3239ae4d2d0a4c298ae6
Author: Zander Brown <zbrown gnome org>
Date:   Mon Oct 7 08:43:08 2019 +0100

    scan-build: fix various "bugs"

 app/layer-editor/dia-layer-editor-dialog.c |   2 +-
 app/textedit.c                             |  17 ++--
 app/toolbox.c                              |   3 +
 app/undo.c                                 |  10 ++-
 lib/arrows.c                               |   2 +-
 lib/beziershape.c                          |  73 ++++++++--------
 lib/dia_svg.c                              |   6 +-
 lib/diatransformrenderer.c                 |   2 +-
 lib/object.c                               |   2 +-
 lib/orth_conn.c                            | 133 +++++++++++++++--------------
 lib/poly_conn.c                            |  62 +++++++-------
 lib/polyshape.c                            |  73 ++++++++--------
 lib/prop_basic.c                           |   4 +-
 lib/prop_matrix.c                          |  40 ++++-----
 lib/text.c                                 |  12 ++-
 lib/widgets.c                              |   4 +-
 objects/custom_lines/line_info.c           |  48 +++++------
 objects/standard/outline.c                 |   2 +-
 plug-ins/drs/dia-render-script-renderer.c  |   2 +-
 plug-ins/python/pydia-properties.c         |  10 ++-
 plug-ins/python/pydia-property.c           |   2 +-
 21 files changed, 265 insertions(+), 244 deletions(-)
---
diff --git a/app/layer-editor/dia-layer-editor-dialog.c b/app/layer-editor/dia-layer-editor-dialog.c
index 402caf8f..70f552c9 100644
--- a/app/layer-editor/dia-layer-editor-dialog.c
+++ b/app/layer-editor/dia-layer-editor-dialog.c
@@ -336,7 +336,7 @@ void
 dia_layer_editor_dialog_set_diagram (DiaLayerEditorDialog *self,
                                      Diagram              *dia)
 {
-  DiaLayerEditorDialogPrivate *priv = dia_layer_editor_dialog_get_instance_private (self);
+  DiaLayerEditorDialogPrivate *priv;
 
   g_return_if_fail (DIA_IS_LAYER_EDITOR_DIALOG (self));
 
diff --git a/app/textedit.c b/app/textedit.c
index 171ec1c6..777548ac 100644
--- a/app/textedit.c
+++ b/app/textedit.c
@@ -268,19 +268,24 @@ textedit_deactivate_focus(void)
   }
 }
 
-/** Call when something should be removed from the focus list.
+/**
+ * textedit_remove_focus:
+ * @obj: the #DiaObject
+ * @diagram: the #Diagram (unused??)
+ *
+ * Call when something should be removed from the focus list.
  * Calling this takes us out of textedit mode.
  */
 void
-textedit_remove_focus(DiaObject *obj, Diagram *diagram)
+textedit_remove_focus (DiaObject *obj, Diagram *diagram)
 {
-  Focus *old_focus = get_active_focus((DiagramData *) diagram);
-  if (remove_focus_object(obj)) {
+  if (remove_focus_object (obj)) {
     /* TODO: make sure the focus is deactivated */
   }
+
   /* This also ends the edit */
-  if (ddisplay_active() != NULL) {
-    textedit_exit(ddisplay_active());
+  if (ddisplay_active () != NULL) {
+    textedit_exit (ddisplay_active ());
   }
 }
 
diff --git a/app/toolbox.c b/app/toolbox.c
index a4356edc..2187eedc 100644
--- a/app/toolbox.c
+++ b/app/toolbox.c
@@ -310,6 +310,9 @@ fill_sheet_wbox(Sheet *sheet)
 
     if (pixbuf) {
       image = gtk_image_new_from_pixbuf (pixbuf);
+    } else {
+      image = gtk_image_new_from_icon_name ("image-missing",
+                                            GTK_ICON_SIZE_SMALL_TOOLBAR);
     }
 
     button = gtk_radio_button_new (tool_group);
diff --git a/app/undo.c b/app/undo.c
index 5afeecfe..0eabadda 100644
--- a/app/undo.c
+++ b/app/undo.c
@@ -118,19 +118,21 @@ undo_remove_redo_info(UndoStack *stack)
 }
 
 void
-undo_push_change(UndoStack *stack, DiaChange *change)
+undo_push_change (UndoStack *stack, DiaChange *change)
 {
   if (stack->current_change != stack->last_change)
-    undo_remove_redo_info(stack);
+    undo_remove_redo_info (stack);
 
   g_debug ("Push %s at %d", DIA_CHANGE_TYPE_NAME (change), stack->depth);
 
   change->prev = stack->last_change;
   change->next = NULL;
-  stack->last_change->next = change;
+  if (stack->last_change) {
+    stack->last_change->next = change;
+  }
   stack->last_change = change;
   stack->current_change = change;
-  undo_update_menus(stack);
+  undo_update_menus (stack);
 }
 
 static void
diff --git a/lib/arrows.c b/lib/arrows.c
index 80889ddb..d1cf42be 100644
--- a/lib/arrows.c
+++ b/lib/arrows.c
@@ -1839,7 +1839,7 @@ draw_rounded (DiaRenderer *renderer,
   Point p = *to;
   Point delta;
   real len, rayon;
-  real rapport;
+  real rapport = 1.0;
   real angle_start;
 
   dia_renderer_set_linewidth (renderer, linewidth);
diff --git a/lib/beziershape.c b/lib/beziershape.c
index 9f27f939..e80c5776 100644
--- a/lib/beziershape.c
+++ b/lib/beziershape.c
@@ -48,7 +48,7 @@ struct BezPointChange {
 
   enum change_type type;
   int applied;
-  
+
   BezPoint point;
   BezCornerType corner_type;
   int pos;
@@ -151,7 +151,7 @@ beziershape_move_handle (BezierShape *bezier,
   int handle_nr, comp_nr;
   int next_nr, prev_nr;
   Point delta, pt;
-  
+
   delta = *to;
   point_sub(&delta, &handle->pos);
 
@@ -163,7 +163,7 @@ beziershape_move_handle (BezierShape *bezier,
     next_nr = 1;
   if (comp_nr == 1)
     prev_nr = bezier->bezier.num_points - 1;
-  
+
   switch(handle->id) {
   case HANDLE_BEZMAJOR:
     if (comp_nr == bezier->bezier.num_points - 1) {
@@ -263,7 +263,7 @@ beziershape_move (BezierShape *bezier, Point *to)
 {
   Point p;
   int i;
-  
+
   p = *to;
   point_sub(&p, &bezier->bezier.points[0].p1);
 
@@ -292,7 +292,7 @@ beziershape_closest_handle (BezierShape *bezier,
   int i, hn;
   real dist = G_MAXDOUBLE;
   Handle *closest = NULL;
-  
+
   for (i = 1, hn = 0; i < bezier->bezier.num_points; i++, hn++) {
     real new_dist;
 
@@ -454,7 +454,7 @@ beziershape_add_segment (BezierShape *bezier,
 
   if (bezier->bezier.points[segment].type == BEZ_CURVE_TO)
     startpoint = bezier->bezier.points[segment].p3;
-  else 
+  else
     startpoint = bezier->bezier.points[segment].p1;
   other = bezier->bezier.points[segment+1].p3;
   if (point == NULL) {
@@ -527,7 +527,7 @@ beziershape_remove_segment (BezierShape *bezier, int pos)
 
   old_cp1 = bezier->object.connections[2*pos-2];
   old_cp2 = bezier->object.connections[2*pos-1];
-  
+
   object_unconnect((DiaObject *)bezier, old_handle1);
   object_unconnect((DiaObject *)bezier, old_handle2);
   object_unconnect((DiaObject *)bezier, old_handle3);
@@ -535,7 +535,7 @@ beziershape_remove_segment (BezierShape *bezier, int pos)
   remove_handles(bezier, pos);
 
   beziershape_update_data(bezier);
-  
+
   return beziershape_create_point_change(bezier, TYPE_REMOVE_POINT,
                                         &old_point, old_ctype, pos,
                                         old_handle1, old_handle2, old_handle3,
@@ -680,9 +680,9 @@ beziershape_update_data (BezierShape *bezier)
   int i;
   Point last;
   Point minp, maxp;
-  
+
   DiaObject *obj = &bezier->object;
-  
+
   /* handle the case of whole points array update (via set_prop) */
   if (3*(bezier->bezier.num_points-1) != obj->num_handles ||
       2*(bezier->bezier.num_points-1) + 1 != obj->num_connections) {
@@ -743,14 +743,14 @@ beziershape_update_data (BezierShape *bezier)
       obj->connections[2*i-1]->pos.x = (last.x + bezier->bezier.points[i].p1.x) / 2;
       obj->connections[2*i-1]->pos.y = (last.y + bezier->bezier.points[i].p1.y) / 2;
     }
-    obj->connections[2*i-1]->directions = 
+    obj->connections[2*i-1]->directions =
       find_slope_directions(slopepoint1, slopepoint2);
     if (bezier->bezier.points[i].type == BEZ_CURVE_TO)
       last = bezier->bezier.points[i].p3;
     else
       last = bezier->bezier.points[i].p1;
   }
-  
+
   /* Find the middle of the object (or some approximation at least) */
   minp = maxp = bezier->bezier.points[0].p1;
   for (i = 1; i < bezier->bezier.num_points; i++) {
@@ -774,7 +774,7 @@ beziershape_update_boundingbox (BezierShape *bezier)
   g_assert(bezier != NULL);
 
   extra = &bezier->extra_spacing;
-  pextra.start_trans = pextra.end_trans = 
+  pextra.start_trans = pextra.end_trans =
     pextra.start_long = pextra.end_long = 0;
   pextra.middle_trans = extra->border_trans;
 
@@ -796,7 +796,7 @@ new_handles_and_connections (BezierShape *bezier, int num_points)
     obj->handles[3*i] = g_new0(Handle,1);
     obj->handles[3*i+1] = g_new0(Handle,1);
     obj->handles[3*i+2] = g_new0(Handle,1);
-  
+
     obj->handles[3*i]->connect_type = HANDLE_NONCONNECTABLE;
     obj->handles[3*i]->connected_to = NULL;
     obj->handles[3*i]->type = HANDLE_MINOR_CONTROL;
@@ -806,7 +806,7 @@ new_handles_and_connections (BezierShape *bezier, int num_points)
     obj->handles[3*i+1]->connected_to = NULL;
     obj->handles[3*i+1]->type = HANDLE_MINOR_CONTROL;
     obj->handles[3*i+1]->id = HANDLE_LEFTCTRL;
-  
+
     obj->handles[3*i+2]->connect_type = HANDLE_NONCONNECTABLE;
     obj->handles[3*i+2]->connected_to = NULL;
     obj->handles[3*i+2]->type = HANDLE_MAJOR_CONTROL;
@@ -827,7 +827,7 @@ new_handles_and_connections (BezierShape *bezier, int num_points)
 }
 
 /** Initialize a bezier object with the given amount of points.
- * The points array of the bezier object might not be previously 
+ * The points array of the bezier object might not be previously
  * initialized with appropriate positions.
  * This will set up handles and make all corners symmetric.
  * @param bezier A newly allocated beziershape object.
@@ -842,7 +842,7 @@ beziershape_init (BezierShape *bezier, int num_points)
   obj = &bezier->object;
 
   object_init(obj, 3*(num_points-1), 2*(num_points-1) + 1);
-  
+
   bezier->bezier.num_points = num_points;
 
   bezier->bezier.points = g_new(BezPoint, num_points);
@@ -888,7 +888,7 @@ beziershape_copy (BezierShape *from, BezierShape *to)
     toobj->connections[i]->flags = fromobj->connections[i]->flags;
   }
 
-  memcpy(&to->extra_spacing,&from->extra_spacing,sizeof(to->extra_spacing));  
+  memcpy(&to->extra_spacing,&from->extra_spacing,sizeof(to->extra_spacing));
   beziershape_update_data(to);
 }
 
@@ -902,26 +902,29 @@ beziershape_destroy (BezierShape *bezier)
   /* Need to store these temporary since object.handles is
      freed by object_destroy() */
   nh = bezier->object.num_handles;
-  temp_handles = g_new(Handle *, nh);
+  temp_handles = g_new0 (Handle *, nh);
   for (i = 0; i < nh; i++)
     temp_handles[i] = bezier->object.handles[i];
 
-  temp_cps = g_new(ConnectionPoint *, bezier->object.num_connections);
-  for (i = 0; i < bezier->object.num_connections; i++)
+  temp_cps = g_new0 (ConnectionPoint *, bezier->object.num_connections);
+  for (i = 0; i < bezier->object.num_connections; i++) {
     temp_cps[i] = bezier->object.connections[i];
-  
-  object_destroy(&bezier->object);
+  }
 
-  for (i = 0; i < nh; i++)
-    g_free(temp_handles[i]);
-  g_free(temp_handles);
-
-  for (i = 0; i < bezier->object.num_connections; i++)
-    g_free(temp_cps[i]);
-  g_free(temp_cps);
-  
-  g_free(bezier->bezier.points);
-  g_free(bezier->bezier.corner_types);
+  object_destroy (&bezier->object);
+
+  for (i = 0; i < nh; i++) {
+    g_free (temp_handles[i]);
+  }
+  g_free (temp_handles);
+
+  for (i = 0; i < bezier->object.num_connections; i++) {
+    g_free (temp_cps[i]);
+  }
+  g_free (temp_cps);
+
+  g_free (bezier->bezier.points);
+  g_free (bezier->bezier.corner_types);
 }
 
 
@@ -971,7 +974,7 @@ beziershape_load (BezierShape *bezier,
   int i;
   AttributeNode attr;
   DataNode data;
-  
+
   DiaObject *obj = &bezier->object;
 
   object_load(obj, obj_node, ctx);
@@ -1187,7 +1190,7 @@ beziershape_corner_change_revert (struct CornerChange *change,
     bezier->bezier.points[1].p1 = change->point_right;
   else
     bezier->bezier.points[comp_nr+1].p1 = change->point_right;
-  bezier->bezier.corner_types[comp_nr] = change->old_type;  
+  bezier->bezier.corner_types[comp_nr] = change->old_type;
   if (comp_nr == 0)
     bezier->bezier.corner_types[bezier->bezier.num_points-1] = change->new_type;
   if (comp_nr == bezier->bezier.num_points - 1)
diff --git a/lib/dia_svg.c b/lib/dia_svg.c
index 7dbd5168..1ccc6200 100644
--- a/lib/dia_svg.c
+++ b/lib/dia_svg.c
@@ -1644,10 +1644,10 @@ dia_svg_parse_transform(const gchar *trans, real scale)
 
     if (_parse_transform (transforms[i], &mat, scale)) {
       if (!m) {
-       m = g_new (DiaMatrix, 1);
-       *m = mat;
+        m = g_new0 (DiaMatrix, 1);
+        *m = mat;
       } else {
-       dia_matrix_multiply (m, &mat, m);
+        dia_matrix_multiply (m, &mat, m);
       }
     }
     ++i;
diff --git a/lib/diatransformrenderer.c b/lib/diatransformrenderer.c
index 65e99b2b..ea50a74d 100644
--- a/lib/diatransformrenderer.c
+++ b/lib/diatransformrenderer.c
@@ -562,7 +562,7 @@ draw_object (DiaRenderer *self,
   g_return_if_fail (renderer->worker != NULL);
 
   if (matrix) {
-    DiaMatrix *m2 = g_new (DiaMatrix, 1);
+    DiaMatrix *m2 = g_new0 (DiaMatrix, 1);
     if (m)
       dia_matrix_multiply (m2, matrix, m);
     else
diff --git a/lib/object.c b/lib/object.c
index 3ae92954..c0da438d 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1309,7 +1309,7 @@ dia_object_type_get_icon (const DiaObjectType *type)
 
   if (g_str_has_prefix ((char *) icon_data, "res:")) {
     pixbuf = pixbuf_from_resource (((char *) icon_data) + 4);
-  } else if (strncmp ((char *) icon_data, "GdkP", 4) == 0) {
+  } else if (icon_data && strncmp ((char *) icon_data, "GdkP", 4) == 0) {
     /* GTK3: We will remove this in Dia 2.0 but is retained to maintain
      * compatability with 0.97.3 objects */
     g_warning ("Object '%s' has an inline icon, this is deprecated",
diff --git a/lib/orth_conn.c b/lib/orth_conn.c
index e7d52476..8040b684 100644
--- a/lib/orth_conn.c
+++ b/lib/orth_conn.c
@@ -31,7 +31,7 @@
 #include "diarenderer.h"
 #include "autoroute.h"
 
-static void place_handle_by_swapping(OrthConn *orth, 
+static void place_handle_by_swapping(OrthConn *orth,
                                      int index, Handle *handle);
 static ObjectChange *orthconn_set_autorouting(OrthConn *orth, gboolean on);
 
@@ -55,12 +55,12 @@ struct MidSegmentChange {
    *
    * None of the end segments must be removed by this change.
    */
-  
+
   enum change_type type;
   int applied;
-  
+
   int segment;
-  Point points[2]; 
+  Point points[2];
   Handle *handles[2]; /* These handles cannot be connected */
   /* NewOrthConn additions */
   ConnectionPoint *conn; /* ? */
@@ -71,7 +71,7 @@ static ObjectChange *
 endsegment_create_change(OrthConn *orth, enum change_type type,
                         int segment, Point *point,
                         Handle *handle);
-static void 
+static void
 place_handle_by_swapping(OrthConn *orth, int index, Handle *handle);
 
 struct EndSegmentChange {
@@ -86,10 +86,10 @@ struct EndSegmentChange {
    * Deleted segments might be connected, so we must store the connection
    * point.
    */
-  
+
   enum change_type type;
   int applied;
-  
+
   int segment;
   Point point;
   Handle *handle;
@@ -151,7 +151,7 @@ static int get_segment_nr(OrthConn *orth, Point *point, real max_dist)
 
   segment = 0;
   distance = distance_line_point(&orth->points[0], &orth->points[1], 0, point);
-  
+
   for (i=1;i<orth->numpoints-1;i++) {
     tmp_dist = distance_line_point(&orth->points[i], &orth->points[i+1], 0, point);
     if (tmp_dist < distance) {
@@ -162,7 +162,7 @@ static int get_segment_nr(OrthConn *orth, Point *point, real max_dist)
 
   if (distance < max_dist)
     return segment;
-  
+
   return -1;
 }
 
@@ -191,7 +191,7 @@ orthconn_move_handle(OrthConn *orth, Handle *handle,
     case VERTICAL:
       orth->points[1].x = to->x;
       break;
-    } 
+    }
     break;
   case HANDLE_MOVE_ENDPOINT:
     n = orth->numpoints - 1;
@@ -222,7 +222,7 @@ orthconn_move_handle(OrthConn *orth, Handle *handle,
       orth->points[handle_nr].x = to->x;
       orth->points[handle_nr+1].x = to->x;
       break;
-    } 
+    }
     break;
   default:
     g_warning("Internal error in orthconn_move_handle.\n");
@@ -237,7 +237,7 @@ orthconn_move(OrthConn *orth, Point *to)
 {
   Point p;
   int i;
-  
+
   p = *to;
   point_sub(&p, &orth->points[0]);
 
@@ -253,7 +253,7 @@ orthconn_distance_from(OrthConn *orth, Point *point, real line_width)
 {
   int i;
   real dist;
-  
+
   dist = distance_line_point( &orth->points[0], &orth->points[1],
                              line_width, point);
   for (i=1;i<orth->numpoints-1;i++) {
@@ -287,9 +287,9 @@ neworthconn_update_midpoints(OrthConn *orth)
 
 static void
 adjust_handle_count_to(OrthConn *orth, gint count) {
-  /* This will shrink or expand orth->handles as necessary (so that 
+  /* This will shrink or expand orth->handles as necessary (so that
      orth->numhandles matches orth->numpoints-1, most probably), by adding or
-     removing minor handles and keeping the endpoint handles at the 
+     removing minor handles and keeping the endpoint handles at the
      extremities of the array. */
 
   if (orth->numhandles == count) return;
@@ -298,8 +298,8 @@ adjust_handle_count_to(OrthConn *orth, gint count) {
     orth->handles = g_realloc(orth->handles,
                               (count)*sizeof(Handle *));
     orth->handles[count-1] = orth->handles[orth->numhandles-1];
-    orth->handles[orth->numhandles-1] = NULL; 
-    for (i=orth->numhandles-1; i<count-1; i++) {  
+    orth->handles[orth->numhandles-1] = NULL;
+    for (i=orth->numhandles-1; i<count-1; i++) {
       Handle *handle = g_new0(Handle,1);
       setup_midpoint_handle(handle);
       object_add_handle(&orth->object,handle);
@@ -319,7 +319,7 @@ adjust_handle_count_to(OrthConn *orth, gint count) {
                          (count)*sizeof(Handle *));
   }
   orth->numhandles = count;
-  /* handles' positions will be set now */ 
+  /* handles' positions will be set now */
 }
 
 void
@@ -348,7 +348,7 @@ orthconn_update_data(OrthConn *orth)
 
   points = orth->points;
   if (!orth->autorouting &&
-      (connpoint_is_autogap(start_cp) || 
+      (connpoint_is_autogap(start_cp) ||
        connpoint_is_autogap(end_cp))) {
     Point* new_points = g_new(Point, orth->numpoints);
     for (i = 0; i < orth->numpoints; i++) {
@@ -413,7 +413,7 @@ orthconn_can_delete_segment(OrthConn *orth, Point *clickedpoint)
   /* Cannot delete any segments when there are only two left,
    * and not amy middle segment if there are only three segments.
    */
-  
+
   if (orth->numpoints==3)
     return 0;
 
@@ -421,7 +421,7 @@ orthconn_can_delete_segment(OrthConn *orth, Point *clickedpoint)
 
   if (segment<0)
     return 0;
-  
+
   if ( (segment != 0) && (segment != orth->numpoints-2)) {
     /* middle segment */
     if (orth->numpoints==4)
@@ -438,12 +438,12 @@ orthconn_can_add_segment(OrthConn *orth, Point *clickedpoint)
 
   if (segment<0)
     return 0;
-  
+
   return 1;
 }
 
 
-/* Needs to have at least 2 handles. 
+/* Needs to have at least 2 handles.
    The handles are stored in order in the OrthConn, but need
    not be stored in order in the DiaObject.handles array. This
    is so that derived object can do what they want with
@@ -457,7 +457,7 @@ orthconn_init(OrthConn *orth, Point *startpoint)
   obj = &orth->object;
 
   object_init(obj, 3, 0);
-  
+
   orth->numpoints = 4;
   orth->numorient = orth->numpoints - 1;
 
@@ -471,11 +471,11 @@ orthconn_init(OrthConn *orth, Point *startpoint)
   orth->handles[0] = g_new(Handle, 1);
   setup_endpoint_handle(orth->handles[0], HANDLE_MOVE_STARTPOINT);
   obj->handles[0] = orth->handles[0];
-  
+
   orth->handles[1] = g_new(Handle, 1);
   setup_midpoint_handle(orth->handles[1]);
   obj->handles[1] = orth->handles[1];
-  
+
   orth->handles[2] = g_new(Handle, 1);
   setup_endpoint_handle(orth->handles[2], HANDLE_MOVE_ENDPOINT);
   obj->handles[2] = orth->handles[2];
@@ -508,19 +508,20 @@ orthconn_init(OrthConn *orth, Point *startpoint)
  * when auto-routing changed the number of points
  */
 void
-orthconn_set_points(OrthConn *orth, int num_points, Point *points) 
+orthconn_set_points (OrthConn *orth, int num_points, Point *points)
 {
   int i;
   gboolean horiz;
 
   orth->numpoints = num_points;
 
-  if (orth->points)
-    g_free(orth->points);
+  if (orth->points) {
+    g_free (orth->points);
+  }
 
-  orth->points = g_malloc((orth->numpoints)*sizeof(Point));
+  orth->points = g_new0 (Point, orth->numpoints);
 
-  for (i=0;i<orth->numpoints;i++) {
+  for (i = 0; i < orth->numpoints; i++) {
     orth->points[i] = points[i];
   }
 
@@ -583,7 +584,7 @@ orthconn_destroy(OrthConn *orth)
 
   connpointline_destroy(orth->midpoints);
   object_destroy(&orth->object);
-  
+
   g_free(orth->points);
   g_free(orth->orientation);
 
@@ -593,7 +594,7 @@ orthconn_destroy(OrthConn *orth)
   g_free(orth->handles);
 }
 
-static void 
+static void
 place_handle_by_swapping(OrthConn *orth, int index, Handle *handle)
 {
   DiaObject *obj;
@@ -610,7 +611,7 @@ place_handle_by_swapping(OrthConn *orth, int index, Handle *handle)
       tmp = obj->handles[j];
       obj->handles[j] = obj->handles[index];
       obj->handles[index] = tmp;
-      
+
       return;
     }
   }
@@ -625,11 +626,11 @@ orthconn_save(OrthConn *orth, ObjectNode obj_node, DiaContext *ctx)
   /* Make sure start-handle is first and end-handle is second. */
   place_handle_by_swapping(orth, 0, orth->handles[0]);
   place_handle_by_swapping(orth, 1, orth->handles[orth->numpoints-2]);
-  
+
   object_save(&orth->object, obj_node, ctx);
 
   attr = new_attribute(obj_node, "orth_points");
-  
+
   for (i=0;i<orth->numpoints;i++) {
     data_add_point(attr, &orth->points[i], ctx);
   }
@@ -651,7 +652,7 @@ orthconn_load(OrthConn *orth, ObjectNode obj_node,
   DataNode data;
   int n;
   int version = 0;
-  
+
   DiaObject *obj = &orth->object;
 
   object_load(obj, obj_node, ctx);
@@ -732,10 +733,10 @@ orthconn_delete_segment(OrthConn *orth, Point *clickedpoint)
 {
   int segment;
   ObjectChange *change = NULL;
-  
+
   if (!orthconn_can_delete_segment(orth, clickedpoint))
     return NULL;
-  
+
   segment = get_segment_nr(orth, clickedpoint, 1.0);
   if (segment < 0)
     return NULL;
@@ -753,8 +754,8 @@ orthconn_delete_segment(OrthConn *orth, Point *clickedpoint)
      * That would delete also the endpoint segment after it.
      */
     if (segment == orth->numpoints-3)
-      segment--; 
-    
+      segment--;
+
     change = midsegment_create_change(orth, TYPE_REMOVE_SEGMENT, segment,
                                      &orth->points[segment],
                                      &orth->points[segment+1],
@@ -763,7 +764,7 @@ orthconn_delete_segment(OrthConn *orth, Point *clickedpoint)
   }
 
   change->apply(change, (DiaObject *)orth);
-  
+
   return change;
 }
 
@@ -774,7 +775,7 @@ orthconn_add_segment(OrthConn *orth, Point *clickedpoint)
   ObjectChange *change = NULL;
   int segment;
   Point newpoint;
-  
+
   if (!orthconn_can_add_segment(orth, clickedpoint))
     return NULL;
 
@@ -804,7 +805,7 @@ orthconn_add_segment(OrthConn *orth, Point *clickedpoint)
       newpoint.y = orth->points[segment].y;
     else
       newpoint.x = orth->points[segment].x;
-    
+
     change = midsegment_create_change(orth, TYPE_ADD_SEGMENT, segment,
                                      &newpoint,
                                      &newpoint,
@@ -836,14 +837,14 @@ static void
 delete_point(OrthConn *orth, int pos)
 {
   int i;
-  
+
   orth->numpoints--;
   orth->numorient = orth->numpoints - 1;
 
   for (i=pos;i<orth->numpoints;i++) {
     orth->points[i] = orth->points[i+1];
   }
-  
+
   orth->points = g_realloc(orth->points, orth->numpoints*sizeof(Point));
 }
 
@@ -857,7 +858,7 @@ remove_handle(OrthConn *orth, int segment)
   Handle *handle;
 
   handle = orth->handles[segment];
-  
+
   for (i=segment; i < orth->numpoints-1; i++) {
     orth->handles[i] = orth->handles[i+1];
     orth->orientation[i] = orth->orientation[i+1];
@@ -867,7 +868,7 @@ remove_handle(OrthConn *orth, int segment)
                              (orth->numpoints-1)*sizeof(Orientation));
   orth->handles = g_realloc(orth->handles,
                          (orth->numpoints-1)*sizeof(Handle *));
-  
+
   object_remove_handle(&orth->object, handle);
   orth->numhandles = orth->numpoints-1;
 }
@@ -877,7 +878,7 @@ static void
 add_point(OrthConn *orth, int pos, Point *point)
 {
   int i;
-  
+
   orth->numpoints++;
   orth->numorient = orth->numpoints-1;
 
@@ -896,7 +897,7 @@ insert_handle(OrthConn *orth, int segment,
              Handle *handle, Orientation orient)
 {
   int i;
-  
+
   orth->orientation = g_realloc(orth->orientation,
                              (orth->numpoints-1)*sizeof(Orientation));
   orth->handles = g_realloc(orth->handles,
@@ -907,7 +908,7 @@ insert_handle(OrthConn *orth, int segment,
   }
   orth->handles[segment] = handle;
   orth->orientation[segment] = orient;
-  
+
   object_add_handle(&orth->object, handle);
   orth->numhandles = orth->numpoints-1;
 }
@@ -952,14 +953,14 @@ endsegment_change_apply(struct EndSegmentChange *change, DiaObject *obj)
                    FLIP_ORIENT(orth->orientation[orth->numpoints-3]) );
       setup_midpoint_handle(orth->handles[orth->numpoints-3]);
       change->cplchange = connpointline_add_point(orth->midpoints,
-                                                 &orth->midpoints->end);      
+                                                 &orth->midpoints->end);
     }
-    if (change->cp) 
+    if (change->cp)
       object_connect(obj, change->handle, change->cp);
     break;
   case TYPE_REMOVE_SEGMENT:
     object_unconnect(obj, change->old_end_handle);
-    change->cplchange = 
+    change->cplchange =
       connpointline_remove_point(orth->midpoints,
                                 &orth->points[change->segment]);
     if (change->segment==0) { /* first */
@@ -982,8 +983,8 @@ static void
 endsegment_change_revert(struct EndSegmentChange *change, DiaObject *obj)
 {
   OrthConn *orth = (OrthConn *)obj;
-  
-  change->cplchange->revert(change->cplchange,obj);    
+
+  change->cplchange->revert(change->cplchange,obj);
   switch (change->type) {
   case TYPE_ADD_SEGMENT:
     object_unconnect(obj, change->handle);
@@ -998,7 +999,7 @@ endsegment_change_revert(struct EndSegmentChange *change, DiaObject *obj)
       setup_endpoint_handle(orth->handles[orth->numpoints-2],
                            HANDLE_MOVE_ENDPOINT);
     }
-    if (change->cp) 
+    if (change->cp)
       object_connect(obj, change->old_end_handle, change->cp);
     break;
   case TYPE_REMOVE_SEGMENT:
@@ -1014,7 +1015,7 @@ endsegment_change_revert(struct EndSegmentChange *change, DiaObject *obj)
                    FLIP_ORIENT(orth->orientation[orth->numpoints-3]) );
       setup_midpoint_handle(orth->handles[orth->numpoints-3]);
     }
-    if (change->cp) 
+    if (change->cp)
       object_connect(obj, change->old_end_handle, change->cp);
     break;
   }
@@ -1064,13 +1065,13 @@ midsegment_change_free(struct MidSegmentChange *change)
   }
 
   if (change->cplchange[0]) {
-    if (change->cplchange[0]->free) 
+    if (change->cplchange[0]->free)
       change->cplchange[0]->free(change->cplchange[0]);
     g_free(change->cplchange[0]);
     change->cplchange[0] = NULL;
   }
   if (change->cplchange[1]) {
-    if (change->cplchange[1]->free) 
+    if (change->cplchange[1]->free)
       change->cplchange[1]->free(change->cplchange[1]);
     g_free(change->cplchange[1]);
     change->cplchange[1] = NULL;
@@ -1093,17 +1094,17 @@ midsegment_change_apply(struct MidSegmentChange *change, DiaObject *obj)
                  orth->orientation[change->segment] );
     insert_handle(orth, change->segment+1, change->handles[0],
                  FLIP_ORIENT(orth->orientation[change->segment]) );
-    change->cplchange[0] = 
+    change->cplchange[0] =
       connpointline_add_point(orth->midpoints,&change->points[0]);
-    change->cplchange[1] = 
+    change->cplchange[1] =
       connpointline_add_point(orth->midpoints,&change->points[1]);
     break;
   case TYPE_REMOVE_SEGMENT:
     seg = change->segment?change->segment:1;
-    change->cplchange[0] = 
+    change->cplchange[0] =
       connpointline_remove_point(orth->midpoints,
                                 &orth->points[seg-1]);
-    change->cplchange[1] = 
+    change->cplchange[1] =
       connpointline_remove_point(orth->midpoints,
                                 &orth->points[seg]);
     delete_point(orth, change->segment);
@@ -1124,7 +1125,7 @@ static void
 midsegment_change_revert(struct MidSegmentChange *change, DiaObject *obj)
 {
   OrthConn *orth = (OrthConn *)obj;
-  
+
   change->cplchange[0]->revert(change->cplchange[0],obj);
   change->cplchange[1]->revert(change->cplchange[1],obj);
 
@@ -1242,7 +1243,7 @@ orthconn_toggle_autorouting_callback(DiaObject *obj, Point *clicked, gpointer da
   /* This is kinda hackish.  Since we can't see the menu item, we have to
    * assume that we're right about toggling and just send !orth->autorouting.
    */
-  change = orthconn_set_autorouting((OrthConn*)obj, 
+  change = orthconn_set_autorouting((OrthConn*)obj,
                                    !((OrthConn*)obj)->autorouting);
   orthconn_update_data((OrthConn *)obj);
   return change;
diff --git a/lib/poly_conn.c b/lib/poly_conn.c
index ea337c33..b640c949 100644
--- a/lib/poly_conn.c
+++ b/lib/poly_conn.c
@@ -37,7 +37,7 @@ struct PointChange {
 
   enum change_type type;
   int applied;
-  
+
   Point point;
   int pos;
 
@@ -58,10 +58,10 @@ typedef enum
   PC_HANDLE_END
 } PolyConnHandleType;
 
-static void 
+static void
 setup_handle(Handle *handle, PolyConnHandleType t)
 {
-  handle->id = (PC_HANDLE_CORNER == t ? HANDLE_CORNER 
+  handle->id = (PC_HANDLE_CORNER == t ? HANDLE_CORNER
                                       : (PC_HANDLE_END == t ? HANDLE_MOVE_ENDPOINT
                                                             : HANDLE_MOVE_STARTPOINT));
   handle->type = (PC_HANDLE_CORNER == t ? HANDLE_MINOR_CONTROL : HANDLE_MAJOR_CONTROL);
@@ -86,7 +86,7 @@ polyconn_move_handle(PolyConn *poly, Handle *handle,
                     HandleMoveReason reason, ModifierKeys modifiers)
 {
   int handle_nr;
-  
+
   handle_nr = get_handle_nr(poly, handle);
   switch(handle->id) {
   case HANDLE_MOVE_STARTPOINT:
@@ -111,7 +111,7 @@ polyconn_move(PolyConn *poly, Point *to)
 {
   Point p;
   int i;
-  
+
   p = *to;
   point_sub(&p, &poly->points[0]);
 
@@ -134,7 +134,7 @@ polyconn_closest_segment(PolyConn *poly, Point *point, real line_width)
                              line_width, point);
   closest = 0;
   for (i=1;i<poly->numpoints-1;i++) {
-    real new_dist = 
+    real new_dist =
       distance_line_point( &poly->points[i], &poly->points[i+1],
                           line_width, point);
     if (new_dist < dist) {
@@ -151,7 +151,7 @@ polyconn_closest_handle(PolyConn *poly, Point *point)
   int i;
   real dist;
   Handle *closest;
-  
+
   closest = poly->object.handles[0];
   dist = distance_point_point( point, &closest->pos);
   for (i=1;i<poly->numpoints;i++) {
@@ -170,7 +170,7 @@ polyconn_distance_from(PolyConn *poly, Point *point, real line_width)
 {
   int i;
   real dist;
-  
+
   dist = distance_line_point( &poly->points[0], &poly->points[1],
                              line_width, point);
   for (i=1;i<poly->numpoints-1;i++) {
@@ -186,7 +186,7 @@ add_handle(PolyConn *poly, int pos, Point *point, Handle *handle)
 {
   int i;
   DiaObject *obj;
-  
+
   poly->numpoints++;
   poly->points = g_realloc(poly->points, poly->numpoints*sizeof(Point));
 
@@ -266,17 +266,17 @@ polyconn_remove_point(PolyConn *poly, int pos)
   Handle *old_handle;
   ConnectionPoint *connectionpoint;
   Point old_point;
-  
+
   old_handle = poly->object.handles[pos];
   old_point = poly->points[pos];
   connectionpoint = old_handle->connected_to;
-  
+
   object_unconnect((DiaObject *)poly, old_handle);
 
   remove_handle(poly, pos);
 
   polyconn_update_data(poly);
-  
+
   return polyconn_create_change(poly, TYPE_REMOVE_POINT,
                                &old_point, pos, old_handle,
                                connectionpoint);
@@ -287,12 +287,12 @@ polyconn_update_data(PolyConn *poly)
 {
   int i;
   DiaObject *obj = &poly->object;
-  
+
   /* handle the case of whole points array update (via set_prop) */
   if (poly->numpoints != obj->num_handles) {
     g_assert(0 == obj->num_connections);
 
-    obj->handles = g_realloc(obj->handles, 
+    obj->handles = g_realloc(obj->handles,
                              poly->numpoints*sizeof(Handle *));
     obj->num_handles = poly->numpoints;
     for (i=0;i<poly->numpoints;i++) {
@@ -332,7 +332,7 @@ polyconn_init(PolyConn *poly, int num_points)
   obj = &poly->object;
 
   object_init(obj, num_points, 0);
-  
+
   poly->numpoints = num_points;
 
   poly->points = g_malloc(num_points*sizeof(Point));
@@ -352,7 +352,7 @@ polyconn_init(PolyConn *poly, int num_points)
 
 /** This function does *not* set up handles */
 void
-polyconn_set_points(PolyConn *poly, int num_points, Point *points) 
+polyconn_set_points(PolyConn *poly, int num_points, Point *points)
 {
   int i;
 
@@ -391,30 +391,32 @@ polyconn_copy(PolyConn *from, PolyConn *to)
   *to->object.handles[toobj->num_handles-1] =
       *from->object.handles[toobj->num_handles-1];
   polyconn_set_points(to, from->numpoints, from->points);
-  
+
   memcpy(&to->extra_spacing,&from->extra_spacing,sizeof(to->extra_spacing));
   polyconn_update_data(to);
 }
 
 void
-polyconn_destroy(PolyConn *poly)
+polyconn_destroy (PolyConn *poly)
 {
   int i;
   Handle **temp_handles;
 
   /* Need to store these temporary since object.handles is
      freed by object_destroy() */
-  temp_handles = g_new(Handle *, poly->numpoints);
-  for (i=0;i<poly->numpoints;i++)
+  temp_handles = g_new0 (Handle *, poly->numpoints);
+  for (i = 0; i <poly->numpoints;i++) {
     temp_handles[i] = poly->object.handles[i];
+  }
+
+  object_destroy (&poly->object);
 
-  object_destroy(&poly->object);
+  for (i = 0; i < poly->numpoints; i++) {
+    g_free (temp_handles[i]);
+  }
+  g_free (temp_handles);
 
-  for (i=0;i<poly->numpoints;i++)
-    g_free(temp_handles[i]);
-  g_free(temp_handles);
-  
-  g_free(poly->points);
+  g_free (poly->points);
 }
 
 
@@ -427,7 +429,7 @@ polyconn_save(PolyConn *poly, ObjectNode obj_node, DiaContext *ctx)
   object_save(&poly->object, obj_node, ctx);
 
   attr = new_attribute(obj_node, "poly_points");
-  
+
   for (i=0;i<poly->numpoints;i++) {
     data_add_point(attr, &poly->points[i], ctx);
   }
@@ -439,7 +441,7 @@ polyconn_load(PolyConn *poly, ObjectNode obj_node, DiaContext *ctx) /* NOTE: Doe
   int i;
   AttributeNode attr;
   DataNode data;
-  
+
   DiaObject *obj = &poly->object;
 
   object_load(obj, obj_node, ctx);
@@ -465,7 +467,7 @@ polyconn_load(PolyConn *poly, ObjectNode obj_node, DiaContext *ctx) /* NOTE: Doe
   obj->handles[0]->connected_to = NULL;
   obj->handles[0]->type = HANDLE_MAJOR_CONTROL;
   obj->handles[0]->id = HANDLE_MOVE_STARTPOINT;
-  
+
   obj->handles[poly->numpoints-1] = g_malloc(sizeof(Handle));
   obj->handles[poly->numpoints-1]->connect_type = HANDLE_CONNECTABLE;
   obj->handles[poly->numpoints-1]->connected_to = NULL;
@@ -520,7 +522,7 @@ polyconn_change_revert(struct PointChange *change, DiaObject *obj)
     if (change->connected_to) {
       object_connect(obj, change->handle, change->connected_to);
     }
-      
+
     break;
   }
   change->applied = 0;
diff --git a/lib/polyshape.c b/lib/polyshape.c
index df0afb35..acaea5ca 100644
--- a/lib/polyshape.c
+++ b/lib/polyshape.c
@@ -40,7 +40,7 @@ struct PointChange {
 
   enum change_type type;
   int applied;
-  
+
   Point point;
   int pos;
 
@@ -79,10 +79,10 @@ polyshape_move_handle(PolyShape *poly, Handle *handle,
                      HandleMoveReason reason, ModifierKeys modifiers)
 {
   int handle_nr;
-  
+
   handle_nr = get_handle_nr(poly, handle);
   poly->points[handle_nr] = *to;
-  
+
   return NULL;
 }
 
@@ -91,7 +91,7 @@ polyshape_move(PolyShape *poly, Point *to)
 {
   Point p;
   int i;
-  
+
   p = *to;
   point_sub(&p, &poly->points[0]);
 
@@ -114,7 +114,7 @@ polyshape_closest_segment(PolyShape *poly, Point *point, real line_width)
                              line_width, point);
   closest = poly->numpoints-1;
   for (i=0;i<poly->numpoints-1;i++) {
-    real new_dist = 
+    real new_dist =
       distance_line_point( &poly->points[i], &poly->points[i+1],
                           line_width, point);
     if (new_dist < dist) {
@@ -131,7 +131,7 @@ polyshape_closest_handle(PolyShape *poly, Point *point)
   int i;
   real dist;
   Handle *closest;
-  
+
   closest = poly->object.handles[0];
   dist = distance_point_point( point, &closest->pos);
   for (i=1;i<poly->numpoints;i++) {
@@ -231,24 +231,24 @@ polyshape_remove_point(PolyShape *poly, int pos)
   Handle *old_handle;
   ConnectionPoint *old_cp1, *old_cp2;
   Point old_point;
-  
+
   old_handle = poly->object.handles[pos];
   old_point = poly->points[pos];
   old_cp1 = poly->object.connections[2*pos];
   old_cp2 = poly->object.connections[2*pos+1];
-  
+
   object_unconnect((DiaObject *)poly, old_handle);
 
   remove_handle(poly, pos);
 
   polyshape_update_data(poly);
-  
+
   return polyshape_create_change(poly, TYPE_REMOVE_POINT,
                                &old_point, pos, old_handle,
                                old_cp1, old_cp2);
 }
 
-/** Returns the first clockwise direction in dirs 
+/** Returns the first clockwise direction in dirs
  * (as returned from find_slope_directions) */
 static gint
 first_direction(gint dirs) {
@@ -261,7 +261,7 @@ first_direction(gint dirs) {
   }
 }
 
-/** Returns the last clockwise direction in dirs 
+/** Returns the last clockwise direction in dirs
  * (as returned from find_slope_directions) */
 static gint
 last_direction(gint dirs) {
@@ -275,7 +275,7 @@ last_direction(gint dirs) {
 }
 
 /** Returns the available directions for a corner */
-static gint 
+static gint
 find_tip_directions(Point prev, Point this, Point next)
 {
   gint startdirs = find_slope_directions(prev, this);
@@ -302,13 +302,13 @@ polyshape_update_data(PolyShape *poly)
   int i;
   DiaObject *obj = &poly->object;
   Point minp, maxp;
-  
+
   /* handle the case of whole points array update (via set_prop) */
   if (poly->numpoints != obj->num_handles ||
       NUM_CONNECTIONS(poly) != obj->num_connections) {
     object_unconnect_all(obj); /* too drastic ? */
 
-    obj->handles = g_realloc(obj->handles, 
+    obj->handles = g_realloc(obj->handles,
                              poly->numpoints*sizeof(Handle *));
     obj->num_handles = poly->numpoints;
     for (i=0;i<poly->numpoints;i++) {
@@ -371,7 +371,7 @@ polyshape_update_boundingbox(PolyShape *poly)
   assert(poly != NULL);
 
   extra = &poly->extra_spacing;
-  pextra.start_trans = pextra.end_trans = 
+  pextra.start_trans = pextra.end_trans =
     pextra.start_long = pextra.end_long = 0;
   pextra.middle_trans = extra->border_trans;
 
@@ -390,7 +390,7 @@ polyshape_init(PolyShape *poly, int num_points)
   obj = &poly->object;
 
   object_init(obj, num_points, 2 * num_points + 1);
-  
+
   poly->numpoints = num_points;
 
   poly->points = g_malloc(num_points*sizeof(Point));
@@ -410,7 +410,7 @@ polyshape_init(PolyShape *poly, int num_points)
     obj->connections[i]->flags = 0;
   }
   obj->connections[obj->num_connections - 1]->flags = CP_FLAGS_MAIN;
-  
+
 
   /* Since the points aren't set yet, and update_data only deals with
      the points, don't call it (Thanks, valgrind!) */
@@ -461,7 +461,7 @@ polyshape_copy(PolyShape *from, PolyShape *to)
 }
 
 void
-polyshape_destroy(PolyShape *poly)
+polyshape_destroy (PolyShape *poly)
 {
   int i;
   Handle **temp_handles;
@@ -469,24 +469,29 @@ polyshape_destroy(PolyShape *poly)
 
   /* Need to store these temporary since object.handles is
      freed by object_destroy() */
-  temp_handles = g_new(Handle *, poly->numpoints);
-  for (i=0;i<poly->numpoints;i++)
+  temp_handles = g_new0 (Handle *, poly->numpoints);
+  for (i = 0; i < poly->numpoints; i++) {
     temp_handles[i] = poly->object.handles[i];
+  }
 
-  temp_cps = g_new(ConnectionPoint *, NUM_CONNECTIONS(poly));
-  for (i = 0; i < NUM_CONNECTIONS(poly); i++)
+  temp_cps = g_new0 (ConnectionPoint *, NUM_CONNECTIONS (poly));
+  for (i = 0; i < NUM_CONNECTIONS (poly); i++) {
     temp_cps[i] = poly->object.connections[i];
+  }
+
+  object_destroy (&poly->object);
 
-  object_destroy(&poly->object);
+  for (i = 0; i < poly->numpoints;i++) {
+    g_free (temp_handles[i]);
+  }
+  g_free (temp_handles);
 
-  for (i=0;i<poly->numpoints;i++)
-    g_free(temp_handles[i]);
-  g_free(temp_handles);
-  for (i = 0; i < NUM_CONNECTIONS(poly); i++)
-    g_free(temp_cps[i]);
-  g_free(temp_cps);
-  
-  g_free(poly->points);
+  for (i = 0; i < NUM_CONNECTIONS (poly); i++) {
+    g_free (temp_cps[i]);
+  }
+  g_free (temp_cps);
+
+  g_free (poly->points);
 }
 
 
@@ -499,7 +504,7 @@ polyshape_save(PolyShape *poly, ObjectNode obj_node, DiaContext *ctx)
   object_save(&poly->object, obj_node, ctx);
 
   attr = new_attribute(obj_node, "poly_points");
-  
+
   for (i=0;i<poly->numpoints;i++) {
     data_add_point(attr, &poly->points[i], ctx);
   }
@@ -511,7 +516,7 @@ polyshape_load(PolyShape *poly, ObjectNode obj_node, DiaContext *ctx) /* NOTE: D
   int i;
   AttributeNode attr;
   DataNode data;
-  
+
   DiaObject *obj = &poly->object;
 
   object_load(obj, obj_node, ctx);
@@ -585,7 +590,7 @@ polyshape_change_revert(struct PointChange *change, DiaObject *obj)
   case TYPE_REMOVE_POINT:
     add_handle((PolyShape *)obj, change->pos, &change->point,
               change->handle, change->cp1, change->cp2);
-      
+
     break;
   }
   change->applied = 0;
diff --git a/lib/prop_basic.c b/lib/prop_basic.c
index c79c0ec5..0dbd8b67 100644
--- a/lib/prop_basic.c
+++ b/lib/prop_basic.c
@@ -232,8 +232,8 @@ void copy_init_property(Property *dest, const Property *src)
 NoopProperty *
 noopprop_new(const PropDescription *pdesc, PropDescToPropPredicate reason)
 {
-  NoopProperty *prop = g_new(NoopProperty,1);
-  initialize_property(&prop->common, pdesc, reason);
+  NoopProperty *prop = g_new0 (NoopProperty, 1);
+  initialize_property (&prop->common, pdesc, reason);
   return prop;
 }
 
diff --git a/lib/prop_matrix.c b/lib/prop_matrix.c
index 8c51ca01..3147d3a1 100644
--- a/lib/prop_matrix.c
+++ b/lib/prop_matrix.c
@@ -45,21 +45,21 @@ matrixprop_new(const PropDescription *pdesc, PropDescToPropPredicate reason)
 }
 
 static void
-matrixprop_free(MatrixProperty *prop) 
+matrixprop_free(MatrixProperty *prop)
 {
   g_free (prop->matrix);
   g_free(prop);
-} 
+}
 
 static MatrixProperty *
-matrixprop_copy(MatrixProperty *src) 
+matrixprop_copy(MatrixProperty *src)
 {
-  MatrixProperty *prop = 
+  MatrixProperty *prop =
     (MatrixProperty *)src->common.ops->new_prop(src->common.descr,
                                               src->common.reason);
 
   prop->matrix = g_memdup (src->matrix, sizeof(DiaMatrix));
-                                             
+
   return prop;
 }
 
@@ -81,7 +81,7 @@ data_matrix (DataNode data)
 {
   DiaMatrix *matrix;
 
-  matrix = g_new (DiaMatrix, 1);
+  matrix = g_new0 (DiaMatrix, 1);
   matrix->xx = _matrix_xml_get_value (data, "xx", 1.0);
   matrix->xy = _matrix_xml_get_value (data, "xy", 0.0);
   matrix->yx = _matrix_xml_get_value (data, "yx", 0.0);
@@ -101,7 +101,7 @@ data_matrix (DataNode data)
   return matrix;
 }
 
-static void 
+static void
 matrixprop_load(MatrixProperty *prop, AttributeNode attr, DataNode data, DiaContext *ctx)
 {
   prop->matrix = data_matrix (data);
@@ -119,7 +119,7 @@ void
 data_add_matrix (AttributeNode attr, DiaMatrix *matrix, DiaContext *ctx)
 {
   DataNode data_node;
-  
+
   data_node = xmlNewChild(attr, NULL, (const xmlChar *)"matrix", NULL);
 
   if (matrix) {
@@ -132,24 +132,24 @@ data_add_matrix (AttributeNode attr, DiaMatrix *matrix, DiaContext *ctx)
   }
 }
 
-static void 
-matrixprop_save(MatrixProperty *prop, AttributeNode attr, DiaContext *ctx) 
+static void
+matrixprop_save(MatrixProperty *prop, AttributeNode attr, DiaContext *ctx)
 {
   if (prop->matrix) {
     data_add_matrix (attr, prop->matrix, ctx);
   }
 }
 
-static void 
+static void
 matrixprop_get_from_offset(MatrixProperty *prop,
-                         void *base, guint offset, guint offset2) 
+                         void *base, guint offset, guint offset2)
 {
   DiaMatrix *matrix = struct_member(base,offset,DiaMatrix *);
 
   prop->matrix = g_memdup (matrix, sizeof (DiaMatrix));
 }
 
-static void 
+static void
 matrixprop_set_from_offset(MatrixProperty *prop,
                            void *base, guint offset, guint offset2)
 {
@@ -163,8 +163,8 @@ matrixprop_set_from_offset(MatrixProperty *prop,
 /* GUI stuff - just the angle for now
  */
 static GtkWidget *
-matrixprop_get_widget (MatrixProperty *prop, PropDialog *dialog) 
-{ 
+matrixprop_get_widget (MatrixProperty *prop, PropDialog *dialog)
+{
   GtkAdjustment *adj;
   GtkWidget *ret, *sb;
   int i;
@@ -186,11 +186,11 @@ matrixprop_get_widget (MatrixProperty *prop, PropDialog *dialog)
     gtk_widget_show(sb);
     gtk_box_pack_start(GTK_BOX(ret), sb, TRUE, TRUE, 0);
   }
-  
+
   return ret;
 }
 
-static void 
+static void
 matrixprop_reset_widget(MatrixProperty *prop, GtkWidget *widget)
 {
   GList *children, *child;
@@ -226,8 +226,8 @@ matrixprop_reset_widget(MatrixProperty *prop, GtkWidget *widget)
   }
 }
 
-static void 
-matrixprop_set_from_widget(MatrixProperty *prop, GtkWidget *widget) 
+static void
+matrixprop_set_from_widget(MatrixProperty *prop, GtkWidget *widget)
 {
   GList *children, *child;
   GtkWidget *sb;
@@ -274,7 +274,7 @@ static const PropertyOps matrixprop_ops = {
   (PropertyType_SetFromOffset) matrixprop_set_from_offset
 };
 
-void 
+void
 prop_matrix_register(void)
 {
   prop_type_register(PROP_TYPE_MATRIX, &matrixprop_ops);
diff --git a/lib/text.c b/lib/text.c
index 105f4622..fd2f493f 100644
--- a/lib/text.c
+++ b/lib/text.c
@@ -498,14 +498,12 @@ text_get_string_copy(const Text *text)
     num += strlen(text_get_line(text, i))+1;
   }
 
-  str = g_malloc(num);
+  str = g_malloc0 (num);
 
-  *str = 0;
-
-  for (i=0;i<text->numlines;i++) {
-    strcat(str, text_get_line(text, i));
-    if (i != (text->numlines-1)) {
-      strcat(str, "\n");
+  for (i = 0; i < text->numlines; i++) {
+    strcat (str, text_get_line (text, i));
+    if (i != (text->numlines - 1)) {
+      strcat (str, "\n");
     }
   }
 
diff --git a/lib/widgets.c b/lib/widgets.c
index c1305e10..141a3032 100644
--- a/lib/widgets.c
+++ b/lib/widgets.c
@@ -775,8 +775,8 @@ dia_toggle_button_new(GtkWidget *on_widget, GtkWidget *off_widget)
 GdkPixbuf *
 pixbuf_from_resource (const gchar *path)
 {
-  GdkPixbufLoader *loader;
-  GdkPixbuf *pixbuf;
+  GdkPixbufLoader *loader = NULL;
+  GdkPixbuf *pixbuf = NULL;
   GBytes *bytes;
 
   g_return_val_if_fail (path != NULL, NULL);
diff --git a/objects/custom_lines/line_info.c b/objects/custom_lines/line_info.c
index c3b6e866..64d31ace 100644
--- a/objects/custom_lines/line_info.c
+++ b/objects/custom_lines/line_info.c
@@ -62,7 +62,7 @@ custom_get_relative_filename(const gchar *current, const gchar *relative)
   return tmp;
 }
 
-static guint 
+static guint
 line_info_get_line_type( const gchar* filename, xmlNodePtr node )
 {
   guint res = CUSTOM_LINETYPE_ZIGZAGLINE;
@@ -78,14 +78,14 @@ line_info_get_line_type( const gchar* filename, xmlNodePtr node )
        res = CUSTOM_LINETYPE_ALL;
   else
        g_warning("%s: `%s' is not a valid line type",filename,tmp);
-       
+
   xmlFree(tmp);
-  
+
   return( res );
 }
 
 
-static guint 
+static guint
 line_info_get_line_style( const gchar* filename, xmlNodePtr node )
 {
   guint res = LINESTYLE_SOLID;
@@ -103,25 +103,25 @@ line_info_get_line_style( const gchar* filename, xmlNodePtr node )
        res = LINESTYLE_DOTTED;
   else
        g_warning("%s: `%s' is not a valid line style", filename, tmp);
-       
+
   xmlFree(tmp);
-  
+
   return( res );
 }
 
-static gfloat 
+static gfloat
 line_info_get_as_float( const gchar* filename, xmlNodePtr node )
 {
   gfloat res = 1.0f;
   xmlChar* tmp = xmlNodeGetContent(node);
 
   res = g_ascii_strtod( (char*)tmp, NULL );
-    
+
   xmlFree(tmp);
-  return( res );  
+  return( res );
 }
 
-static guint 
+static guint
 line_info_get_arrow_type( const gchar* filename, xmlNodePtr node )
 {
   guint res = ARROW_NONE;
@@ -197,13 +197,13 @@ line_info_get_arrow_type( const gchar* filename, xmlNodePtr node )
        res = ARROW_THREE_DOTS;
   else
        g_warning("%s: `%s' is not a valid arrow style", filename, tmp);
-       
+
   xmlFree(tmp);
-  
+
   return( res );
 }
 
-static void 
+static void
 line_info_get_arrow( const gchar* filename, xmlNodePtr node, Arrow* arrow )
 {
   xmlNodePtr child_node = NULL;
@@ -222,7 +222,7 @@ line_info_get_arrow( const gchar* filename, xmlNodePtr node, Arrow* arrow )
   }
 }
 
-static void 
+static void
 line_info_get_arrows( const gchar* filename, xmlNodePtr node, LineInfo* info )
 {
   xmlNodePtr child_node = NULL;
@@ -240,7 +240,7 @@ line_info_get_arrows( const gchar* filename, xmlNodePtr node, LineInfo* info )
 }
 
 
-static void 
+static void
 line_info_get_line_color( const gchar* filename, xmlNodePtr node, LineInfo* info )
 {
   xmlNodePtr child_node = NULL;
@@ -265,7 +265,7 @@ LineInfo* line_info_load_and_apply_from_xmlfile(const gchar *filename, LineInfo*
 LineInfo* line_info_load(const gchar *filename)
 {
   LineInfo* res = g_new0(LineInfo, 1);
-  
+
   res->line_info_filename = g_strdup(filename);
 
   res->name = "CustomLines - Default";
@@ -283,15 +283,15 @@ LineInfo* line_info_load(const gchar *filename)
   res->end_arrow.type = ARROW_NONE;
 
   /* warning: possible memory leak */
-  res = line_info_load_and_apply_from_xmlfile( filename, res );
-  
-  return( res );
+  res = line_info_load_and_apply_from_xmlfile (filename, res);
+
+  return res;
 }
 
 LineInfo* line_info_clone(LineInfo* info)
 {
   LineInfo* res = g_new0(LineInfo, 1);
-  
+
   res->line_info_filename = g_strdup(info->line_info_filename);
 
   res->name              = info->name;
@@ -308,18 +308,18 @@ LineInfo* line_info_clone(LineInfo* info)
   res->start_arrow.type   = info->start_arrow.type;
   res->start_arrow.length = (info->start_arrow.length > 0) ?
                                   info->start_arrow.length : 1.0;
-  res->start_arrow.width  = (info->start_arrow.width > 0) ? 
+  res->start_arrow.width  = (info->start_arrow.width > 0) ?
                                   info->start_arrow.width : 1.0;
   res->end_arrow.type     = info->end_arrow.type;
-  res->end_arrow.length   = (info->end_arrow.length > 0) ? 
+  res->end_arrow.length   = (info->end_arrow.length > 0) ?
                                   info->end_arrow.length : 1.0;
-  res->end_arrow.width           = (info->end_arrow.width > 0) ? 
+  res->end_arrow.width           = (info->end_arrow.width > 0) ?
                                   info->end_arrow.width : 1.0;
 
   return( res );
 }
 
-LineInfo* 
+LineInfo*
 line_info_load_and_apply_from_xmlfile(const gchar *filename, LineInfo* info)
 {
   xmlErrorPtr error_xml = NULL;
diff --git a/objects/standard/outline.c b/objects/standard/outline.c
index 85364058..3591ec65 100644
--- a/objects/standard/outline.c
+++ b/objects/standard/outline.c
@@ -363,7 +363,7 @@ outline_draw (Outline *outline, DiaRenderer *renderer)
   if (total < 2)
     return;
 
-  pts = g_alloca (sizeof(BezPoint)*(total));
+  pts = g_newa (BezPoint, total);
   for (i=0; i < outline->path->num_data; i += outline->path->data[i].header.length) {
     cairo_path_data_t *data = &outline->path->data[i];
     if (CAIRO_PATH_MOVE_TO == data->header.type) {
diff --git a/plug-ins/drs/dia-render-script-renderer.c b/plug-ins/drs/dia-render-script-renderer.c
index 12286530..0d7c008f 100644
--- a/plug-ins/drs/dia-render-script-renderer.c
+++ b/plug-ins/drs/dia-render-script-renderer.c
@@ -174,7 +174,7 @@ draw_object(DiaRenderer *self,
     object_save_props (object, props_node, renderer->ctx);
   }
   if (matrix) {
-    DiaMatrix *m2 = g_new (DiaMatrix, 1);
+    DiaMatrix *m2 = g_new0 (DiaMatrix, 1);
     if (m)
       dia_matrix_multiply (m2, matrix, m);
     else
diff --git a/plug-ins/python/pydia-properties.c b/plug-ins/python/pydia-properties.c
index 3f41d4a2..68c1b08f 100644
--- a/plug-ins/python/pydia-properties.c
+++ b/plug-ins/python/pydia-properties.c
@@ -173,14 +173,16 @@ PyDiaProperties_Length (PyDiaProperties* self)
   if (self->nprops < 0) {
     const PropDescription *desc = NULL;
 
-    if (self->object->ops->describe_props)
-      desc = self->object->ops->describe_props(self->object);
+    if (self->object->ops->describe_props) {
+      desc = dia_object_describe_properties (self->object);
+    }
 
     self->nprops = 0;
     if (desc) {
       int i;
-      for (i = 0; desc[i].name; i++)
+      for (i = 0; desc[i].name; i++) {
         self->nprops++;
+      }
     }
   }
 
@@ -250,7 +252,7 @@ PyDiaProperties_AssSub (PyDiaProperties* self, PyObject *key, PyObject *val)
 }
 
 static PyMappingMethods PyDiaProperties_AsMapping = {
-       (inquiry)PyDiaProperties_Length, /*mp_length*/
+       (lenfunc)PyDiaProperties_Length, /*mp_length*/
        (binaryfunc)PyDiaProperties_Subscript, /*mp_subscript*/
        (objobjargproc)PyDiaProperties_AssSub, /*mp_ass_subscript*/
 };
diff --git a/plug-ins/python/pydia-property.c b/plug-ins/python/pydia-property.c
index 6922630b..401d1ecb 100644
--- a/plug-ins/python/pydia-property.c
+++ b/plug-ins/python/pydia-property.c
@@ -297,7 +297,7 @@ PyDia_set_Matrix (Property *prop, PyObject *val)
 
   if (val->ob_type == &PyDiaMatrix_Type) {
     if (!p->matrix)
-      p->matrix = g_new (DiaMatrix, 1);
+      p->matrix = g_new0 (DiaMatrix, 1);
     *p->matrix = ((PyDiaMatrix *)val)->matrix;
     return 0;
   }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]