[dia] general: use g_[re]new rather than plain [m,re]alloc



commit d15c2030d39c8863eb5474264e7a3b2066ac2701
Author: Zander Brown <zbrown gnome org>
Date:   Fri Jul 30 03:11:08 2021 +0100

    general: use g_[re]new rather than plain [m,re]alloc
    
    Quite a few places could do with being G[Ptr]Arrays rather than
    manual pointer fun but that can be addressed later
    
    Fix https://gitlab.gnome.org/GNOME/dia/-/issues/504

 app/app_procs.c                        |   2 +-
 app/undo.c                             |   6 +-
 lib/bezier-common.c                    |   6 +-
 lib/bezier_conn.c                      |  20 ++++---
 lib/beziershape.c                      |  24 +++++---
 lib/dia-change.c                       |   2 +-
 lib/dia-object-change.c                |   2 +-
 lib/dia_image.c                        |   4 +-
 lib/dia_xml.c                          |  12 ++--
 lib/diagramdata.c                      |  12 ++--
 lib/diarenderer.c                      |   7 +--
 lib/object.c                           |  29 ++++------
 lib/orth_conn.c                        | 103 +++++++++++++++++----------------
 lib/poly_conn.c                        |  81 +++++++++++++-------------
 lib/polyshape.c                        |  58 +++++++++++--------
 lib/text.c                             |   6 +-
 objects/AADL/aadlbox.c                 |  35 ++++++-----
 objects/AADL/edit_port_declaration.c   |   8 ++-
 objects/Database/compound.c            |  45 +++++++-------
 objects/Database/table.c               |  19 +++---
 objects/ER/attribute.c                 |   6 +-
 objects/ER/entity.c                    |   6 +-
 objects/ER/participation.c             |   4 +-
 objects/ER/relationship.c              |   4 +-
 objects/FS/flow-ortho.c                |   4 +-
 objects/FS/flow.c                      |   6 +-
 objects/FS/function.c                  |  87 ++++++++++++++--------------
 objects/GRAFCET/action.c               |   2 +-
 objects/GRAFCET/condition.c            |   2 +-
 objects/GRAFCET/vector.c               |   2 +-
 objects/Istar/actor.c                  |   2 +-
 objects/Istar/goal.c                   |   2 +-
 objects/Istar/link.c                   |   2 +-
 objects/Istar/other.c                  |   2 +-
 objects/Jackson/domain.c               |   2 +-
 objects/Jackson/phenomenon.c           |   2 +-
 objects/Jackson/requirement.c          |   2 +-
 objects/KAOS/goal.c                    |   2 +-
 objects/KAOS/metaandorrel.c            |   2 +-
 objects/KAOS/metabinrel.c              |   2 +-
 objects/KAOS/other.c                   |   2 +-
 objects/Misc/grid_object.c             |   7 ++-
 objects/Misc/tree.c                    |  62 +++++++++-----------
 objects/SADT/annotation.c              |   2 +-
 objects/SADT/arrow.c                   |   2 +-
 objects/SADT/box.c                     |   2 +-
 objects/UML/activity.c                 |   2 +-
 objects/UML/actor.c                    |   2 +-
 objects/UML/association.c              |   4 +-
 objects/UML/branch.c                   |   2 +-
 objects/UML/class.c                    |  20 ++++---
 objects/UML/class_dialog.c             |  12 ++--
 objects/UML/classicon.c                |   2 +-
 objects/UML/component.c                |   2 +-
 objects/UML/constraint.c               |   2 +-
 objects/UML/fork.c                     |   2 +-
 objects/UML/implements.c               |   2 +-
 objects/UML/large_package.c            |   2 +-
 objects/UML/lifeline.c                 |   2 +-
 objects/UML/message.c                  |   2 +-
 objects/UML/node.c                     |   2 +-
 objects/UML/note.c                     |   2 +-
 objects/UML/object.c                   |   2 +-
 objects/UML/realizes.c                 |   2 +-
 objects/UML/small_package.c            |   2 +-
 objects/UML/state.c                    |   2 +-
 objects/UML/state_term.c               |   2 +-
 objects/UML/umlattribute.c             |   2 +-
 objects/UML/umlformalparameter.c       |   2 +-
 objects/UML/umloperation.c             |   2 +-
 objects/UML/umlparameter.c             |   2 +-
 objects/UML/usecase.c                  |   2 +-
 objects/custom/custom_object.c         |   4 +-
 objects/custom/shape_info.c            |  38 +++++++-----
 objects/custom/shape_info.h            |  25 ++++++--
 objects/flowchart/box.c                |   4 +-
 objects/flowchart/diamond.c            |   4 +-
 objects/flowchart/ellipse.c            |   4 +-
 objects/flowchart/parallelogram.c      |   4 +-
 objects/network/bus.c                  |  50 ++++++++--------
 objects/network/wanlink.c              |   6 +-
 objects/standard/arc.c                 |   6 +-
 objects/standard/beziergon.c           |   4 +-
 objects/standard/box.c                 |   6 +-
 objects/standard/ellipse.c             |   6 +-
 objects/standard/image.c               |   4 +-
 objects/standard/line.c                |   6 +-
 objects/standard/polygon.c             |   4 +-
 objects/standard/polyline.c            |   6 +-
 objects/standard/textobj.c             |   6 +-
 objects/standard/zigzagline.c          |   6 +-
 plug-ins/dxf/dxf-import.c              |   4 +-
 plug-ins/postscript/diapsrenderer.c    |   2 +-
 plug-ins/postscript/paginate_psprint.c |   2 +-
 plug-ins/svg/svg-import.c              |   8 +--
 plug-ins/vdx/vdx-export.c              |   2 +-
 plug-ins/xfig/xfig-export.c            |   2 +-
 plug-ins/xfig/xfig-import.c            |  36 +++++++-----
 plug-ins/xslt/xslt.c                   |   2 +-
 99 files changed, 543 insertions(+), 491 deletions(-)
---
diff --git a/app/app_procs.c b/app/app_procs.c
index 6c3116971..0d08a18d5 100644
--- a/app/app_procs.c
+++ b/app/app_procs.c
@@ -98,7 +98,7 @@ build_output_file_name(const char *infname, const char *format, const char *outd
   if (!pe)
     return g_strconcat(outdir ? outdir : "", pp,".",format,NULL);
 
-  tmp = g_malloc0(strlen(pp)+1+strlen(format)+1);
+  tmp = g_new0 (char, strlen (pp) + 1 + strlen (format) + 1);
   memcpy(tmp,pp,pe-pp);
   strcat(tmp,".");
   strcat(tmp,format);
diff --git a/app/undo.c b/app/undo.c
index f32155b1b..3d652af7a 100644
--- a/app/undo.c
+++ b/app/undo.c
@@ -1720,14 +1720,14 @@ DiaChange *
 dia_mem_swap_change_new (Diagram *dia, gpointer dest, gsize size)
 {
   DiaMemSwapChange *change = dia_change_new (DIA_TYPE_MEM_SWAP_CHANGE);
-  gsize i;
 
   change->dest = dest;
   change->size = size;
-  change->mem = g_malloc (size);
+  change->mem = g_new0 (guint8, size);
   /* initialize for swap */
-  for (i = 0; i < size; ++i)
+  for (gsize i = 0; i < size; ++i) {
     change->mem[i] = change->dest[i];
+  }
 
   undo_push_change (dia->undo, DIA_CHANGE (change));
 
diff --git a/lib/bezier-common.c b/lib/bezier-common.c
index 0104d0924..3edb1ee41 100644
--- a/lib/bezier-common.c
+++ b/lib/bezier-common.c
@@ -44,7 +44,9 @@ bezier_calc_corner_types (BezierCommon *bezier)
 
   g_return_if_fail (bezier->num_points > 1);
 
-  bezier->corner_types = g_realloc (bezier->corner_types, bezier->num_points * sizeof(BezCornerType));
+  bezier->corner_types = g_renew (BezCornerType,
+                                  bezier->corner_types,
+                                  bezier->num_points);
   bezier->corner_types[0] = BEZ_CORNER_CUSP;
   bezier->corner_types[num-1] = BEZ_CORNER_CUSP;
 
@@ -87,7 +89,7 @@ beziercommon_set_points (BezierCommon   *bezier,
 
   bezier->num_points = num_points;
 
-  bezier->points = g_realloc(bezier->points, (bezier->num_points)*sizeof(BezPoint));
+  bezier->points = g_renew (BezPoint, bezier->points, bezier->num_points);
 
   for (i=0;i<bezier->num_points;i++) {
     /* to make editing in Dia more convenient we turn line-to to curve-to with cusp controls */
diff --git a/lib/bezier_conn.c b/lib/bezier_conn.c
index 001efac56..3917bbcaf 100644
--- a/lib/bezier_conn.c
+++ b/lib/bezier_conn.c
@@ -408,10 +408,12 @@ add_handles (BezierConn    *bezier,
 
   bezier->bezier.num_points++;
   next = pos + 1;
-  bezier->bezier.points = g_realloc (bezier->bezier.points,
-                                     bezier->bezier.num_points * sizeof (BezPoint));
-  bezier->bezier.corner_types = g_realloc (bezier->bezier.corner_types,
-                                           bezier->bezier.num_points * sizeof (BezCornerType));
+  bezier->bezier.points = g_renew (BezPoint,
+                                   bezier->bezier.points,
+                                   bezier->bezier.num_points);
+  bezier->bezier.corner_types = g_renew (BezCornerType,
+                                         bezier->bezier.corner_types,
+                                         bezier->bezier.num_points);
 
   for (i = bezier->bezier.num_points - 1; i > pos; i--) {
     bezier->bezier.points[i] = bezier->bezier.points[i - 1];
@@ -467,10 +469,12 @@ remove_handles (BezierConn *bezier, int pos)
     bezier->bezier.corner_types[i] = bezier->bezier.corner_types[i + 1];
   }
   bezier->bezier.points[pos].p1 = tmppoint;
-  bezier->bezier.points = g_realloc (bezier->bezier.points,
-                                     bezier->bezier.num_points * sizeof (BezPoint));
-  bezier->bezier.corner_types = g_realloc (bezier->bezier.corner_types,
-                                           bezier->bezier.num_points * sizeof (BezCornerType));
+  bezier->bezier.points = g_renew (BezPoint,
+                                   bezier->bezier.points,
+                                   bezier->bezier.num_points);
+  bezier->bezier.corner_types = g_renew (BezCornerType,
+                                         bezier->bezier.corner_types,
+                                         bezier->bezier.num_points);
 
   old_handle1 = obj->handles[3 * pos - 2];
   old_handle2 = obj->handles[3 * pos - 1];
diff --git a/lib/beziershape.c b/lib/beziershape.c
index 7ced5ec87..19f8ed058 100644
--- a/lib/beziershape.c
+++ b/lib/beziershape.c
@@ -378,11 +378,14 @@ add_handles (BezierShape *bezier,
 
   bezier->bezier.num_points++;
   next = pos + 1;
-  bezier->bezier.points = g_realloc(bezier->bezier.points, bezier->bezier.num_points*sizeof(BezPoint));
+  bezier->bezier.points = g_renew (BezPoint,
+                                   bezier->bezier.points,
+                                   bezier->bezier.num_points);
   if (pos == bezier->bezier.num_points - 1)
     next = 1;
-  bezier->bezier.corner_types = g_realloc(bezier->bezier.corner_types,
-                                  bezier->bezier.num_points * sizeof(BezCornerType));
+  bezier->bezier.corner_types = g_renew (BezCornerType,
+                                         bezier->bezier.corner_types,
+                                         bezier->bezier.num_points);
 
   for (i = bezier->bezier.num_points - 1; i > pos; i--) {
     bezier->bezier.points[i] = bezier->bezier.points[i-1];
@@ -437,10 +440,13 @@ remove_handles (BezierShape *bezier, int pos)
     bezier->bezier.points[1].p1 = bezier->bezier.points[0].p1;
     point_sub(&bezier->bezier.points[1].p1, &controlvector);
   }
-  bezier->bezier.points = g_realloc(bezier->bezier.points,
-                            bezier->bezier.num_points * sizeof(BezPoint));
-  bezier->bezier.corner_types = g_realloc(bezier->bezier.corner_types,
-                               bezier->bezier.num_points * sizeof(BezCornerType));
+
+  bezier->bezier.points = g_renew (BezPoint,
+                                   bezier->bezier.points,
+                                   bezier->bezier.num_points);
+  bezier->bezier.corner_types = g_renew (BezCornerType,
+                                         bezier->bezier.corner_types,
+                                         bezier->bezier.num_points);
 
   old_handle1 = obj->handles[3*pos-3];
   old_handle2 = obj->handles[3*pos-2];
@@ -776,7 +782,9 @@ beziershape_update_data (BezierShape *bezier)
 
     new_handles_and_connections(bezier, bezier->bezier.num_points);
 
-    bezier->bezier.corner_types = g_realloc(bezier->bezier.corner_types, 
bezier->bezier.num_points*sizeof(BezCornerType));
+    bezier->bezier.corner_types = g_renew (BezCornerType,
+                                           bezier->bezier.corner_types,
+                                           bezier->bezier.num_points);
     for (i = 0; i < bezier->bezier.num_points; i++)
       bezier->bezier.corner_types[i] = BEZ_CORNER_SYMMETRIC;
   }
diff --git a/lib/dia-change.c b/lib/dia-change.c
index 006f26d62..e9475c524 100644
--- a/lib/dia-change.c
+++ b/lib/dia-change.c
@@ -187,7 +187,7 @@ g_value_change_transform_value (const GValue *src_value,
 GType
 dia_change_get_type (void)
 {
-  static volatile GType type_id = 0;
+  static GType type_id = 0;
 
   if (g_once_init_enter (&type_id)) {
     static const GTypeFundamentalInfo finfo = {
diff --git a/lib/dia-object-change.c b/lib/dia-object-change.c
index c97995290..cd74f1594 100644
--- a/lib/dia-object-change.c
+++ b/lib/dia-object-change.c
@@ -205,7 +205,7 @@ g_value_change_transform_value (const GValue *src_value,
 GType
 dia_object_change_get_type (void)
 {
-  static volatile GType type_id = 0;
+  static GType type_id = 0;
 
   if (g_once_init_enter (&type_id)) {
     static const GTypeFundamentalInfo finfo = {
diff --git a/lib/dia_image.c b/lib/dia_image.c
index 8917ed70d..d781aa427 100644
--- a/lib/dia_image.c
+++ b/lib/dia_image.c
@@ -426,7 +426,7 @@ dia_image_rgb_data (const DiaImage *image)
   int height = dia_image_height (image);
   int rowstride = dia_image_rowstride (image);
   int size = height * rowstride;
-  guint8 *rgb_pixels = g_try_malloc (size);
+  guint8 *rgb_pixels = g_try_new (guint8, size);
 
   if (!rgb_pixels) {
     return NULL;
@@ -476,7 +476,7 @@ dia_image_mask_data (const DiaImage *image)
   size = gdk_pixbuf_get_width (image->image) *
                                        gdk_pixbuf_get_height(image->image);
 
-  mask = g_try_malloc (size);
+  mask = g_try_new (guint8, size);
   if (!mask) {
     return NULL;
   }
diff --git a/lib/dia_xml.c b/lib/dia_xml.c
index b5efbeacd..b1fcf9496 100644
--- a/lib/dia_xml.c
+++ b/lib/dia_xml.c
@@ -148,7 +148,7 @@ xml_file_check_encoding (const char *filename,
     return res;
   }
 
-  p = buf = g_malloc0 (BUFLEN);
+  p = buf = g_new0 (char, BUFLEN);
   len = gzread (zf, buf, BUFLEN);
   pmax = p + len;
 
@@ -922,9 +922,11 @@ data_string(DataNode data, DiaContext *ctx)
   }
 
   val = xmlGetProp(data, (const xmlChar *)"val");
-  if (val != NULL) { /* Old kind of string. Left for backwards compatibility */
-    str  = g_malloc(4 * (sizeof(char)*(xmlStrlen(val)+1))); /* extra room
-                                                            for UTF8 */
+  if (val != NULL) {
+    /* Old kind of string. Left for backwards compatibility */
+    /* TODO: This "extra room" feels like nonsense, especially when introduced
+     * when this was already legacy */
+    str  = g_new0 (char, 4 * (xmlStrlen (val) + 1)); /* extra room for UTF8 */
     p = str;
     while (*val) {
       if (*val == '\\') {
@@ -965,7 +967,7 @@ data_string(DataNode data, DiaContext *ctx)
 
     len = strlen(p)-1; /* Ignore first '#' */
 
-    str = g_malloc(len+1);
+    str = g_new0 (char, len + 1);
 
     strncpy(str, p+1, len);
     str[len]=0; /* For safety */
diff --git a/lib/diagramdata.c b/lib/diagramdata.c
index 9965898ec..6709e8b1d 100644
--- a/lib/diagramdata.c
+++ b/lib/diagramdata.c
@@ -680,16 +680,20 @@ find_object_highlight(GList *list, DiaObject *obj)
   return NULL;
 }
 
+
 void
-data_highlight_add(DiagramData *data, DiaObject *obj, DiaHighlightType type)
+data_highlight_add (DiagramData *data, DiaObject *obj, DiaHighlightType type)
 {
   ObjectHighlight *oh;
-  if (find_object_highlight (data->highlighted, obj))
+
+  if (find_object_highlight (data->highlighted, obj)) {
     return; /* should this be an error?`*/
-  oh = g_malloc(sizeof(ObjectHighlight));
+  }
+
+  oh = g_new0 (ObjectHighlight, 1);
   oh->obj = obj;
   oh->type = type;
-  data->highlighted = g_list_prepend(data->highlighted, oh);
+  data->highlighted = g_list_prepend (data->highlighted, oh);
 }
 
 
diff --git a/lib/diarenderer.c b/lib/diarenderer.c
index 38d85de9e..3c3121014 100644
--- a/lib/diarenderer.c
+++ b/lib/diarenderer.c
@@ -849,8 +849,7 @@ bezier_add_point(BezierApprox *bezier,
   /* Grow if needed: */
   if (bezier->currpoint == bezier->numpoints) {
     bezier->numpoints += 40;
-    bezier->points = g_realloc(bezier->points,
-                               bezier->numpoints*sizeof(Point));
+    bezier->points = g_renew (Point, bezier->points, bezier->numpoints);
   }
 
   bezier->points[bezier->currpoint] = *point;
@@ -1026,7 +1025,7 @@ draw_bezier (DiaRenderer *renderer,
 
   if (bezier->points == NULL) {
     bezier->numpoints = 30;
-    bezier->points = g_malloc(bezier->numpoints*sizeof(Point));
+    bezier->points = g_new0 (Point, bezier->numpoints);
   }
 
   bezier->currpoint = 0;
@@ -1066,7 +1065,7 @@ draw_beziergon (DiaRenderer *renderer,
 
   if (bezier->points == NULL) {
     bezier->numpoints = 30;
-    bezier->points = g_malloc(bezier->numpoints*sizeof(Point));
+    bezier->points = g_new0 (Point, bezier->numpoints);
   }
 
   bezier->currpoint = 0;
diff --git a/lib/object.c b/lib/object.c
index f54aa0827..b502cb563 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -49,18 +49,13 @@ object_init (DiaObject *obj,
              int        num_connections)
 {
   obj->num_handles = num_handles;
-  if (num_handles > 0)
-    obj->handles = g_malloc0 (sizeof (Handle *) * num_handles);
-  else
-    obj->handles = NULL;
+  obj->handles = g_new0 (Handle *, num_handles);
 
   obj->num_connections = num_connections;
-  if (num_connections > 0)
-    obj->connections = g_malloc0 (sizeof (ConnectionPoint *) * num_connections);
-  else
-    obj->connections = NULL;
+  obj->connections = g_new0 (ConnectionPoint *, num_connections);
 }
 
+
 /**
  * object_destroy:
  * @obj: The object being destroyed.
@@ -626,8 +621,7 @@ object_add_handle_at (DiaObject *obj, Handle *handle, int pos)
 
   obj->num_handles++;
 
-  obj->handles =
-    g_realloc (obj->handles, obj->num_handles * sizeof (Handle *));
+  obj->handles = g_renew (Handle *, obj->handles, obj->num_handles);
 
   for (i = obj->num_handles - 1; i > pos; i--) {
     obj->handles[i] = obj->handles[i - 1];
@@ -669,8 +663,7 @@ object_remove_handle (DiaObject *obj, Handle *handle)
 
   obj->num_handles--;
 
-  obj->handles =
-    g_realloc (obj->handles, obj->num_handles * sizeof (Handle *));
+  obj->handles = g_renew (Handle *, obj->handles, obj->num_handles);
 }
 
 
@@ -709,9 +702,9 @@ object_add_connectionpoint_at (DiaObject       *obj,
 
   obj->num_connections++;
 
-  obj->connections =
-    g_realloc (obj->connections,
-               obj->num_connections * sizeof (ConnectionPoint *));
+  obj->connections = g_renew (ConnectionPoint *,
+                              obj->connections,
+                              obj->num_connections);
 
   for (i = obj->num_connections - 1; i > pos; i--) {
     obj->connections[i] = obj->connections[i - 1];
@@ -758,9 +751,9 @@ object_remove_connectionpoint (DiaObject *obj, ConnectionPoint *conpoint)
 
   obj->num_connections--;
 
-  obj->connections =
-    g_realloc (obj->connections,
-               obj->num_connections * sizeof (ConnectionPoint *));
+  obj->connections = g_renew (ConnectionPoint *,
+                              obj->connections,
+                              obj->num_connections);
 }
 
 
diff --git a/lib/orth_conn.c b/lib/orth_conn.c
index 0be707a90..3258694b7 100644
--- a/lib/orth_conn.c
+++ b/lib/orth_conn.c
@@ -340,45 +340,46 @@ neworthconn_update_midpoints(OrthConn *orth)
 }
 
 
-
-
 static void
-adjust_handle_count_to(OrthConn *orth, gint count) {
+adjust_handle_count_to (OrthConn *orth, int count)
+{
   /* 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
      extremities of the array. */
 
-  if (orth->numhandles == count) return;
-  if (orth->numhandles < count) { /* adding */
-    int i;
-    orth->handles = g_realloc(orth->handles,
-                              (count)*sizeof(Handle *));
+  if (orth->numhandles == count) {
+    return;
+  }
+
+  if (orth->numhandles < count) {
+    /* adding */
+    orth->handles = g_renew (Handle *, orth->handles, count);
     orth->handles[count-1] = orth->handles[orth->numhandles-1];
     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);
+    for (int i = orth->numhandles - 1; i < count - 1; i++) {
+      Handle *handle = g_new0 (Handle, 1);
+      setup_midpoint_handle (handle);
+      object_add_handle (&orth->object,handle);
       orth->handles[i] = handle;
     }
-  } else {  /* removing */
-    int i;
-    for (i=count-1; i<orth->numhandles-1; i++) {
+  } else {
+    /* removing */
+    for (int i = count - 1; i < orth->numhandles - 1; i++) {
       Handle *handle = orth->handles[i];
-      object_remove_handle(&orth->object,handle);
+      object_remove_handle (&orth->object,handle);
       g_clear_pointer (&handle, g_free);
       orth->handles[i] = NULL;
     }
     orth->handles[count-1] = orth->handles[orth->numhandles-1];
     orth->handles[orth->numhandles-1] = NULL;
-    orth->handles = g_realloc(orth->handles,
-                         (count)*sizeof(Handle *));
+    orth->handles = g_renew (Handle *, orth->handles, count);
   }
   orth->numhandles = count;
   /* handles' positions will be set now */
 }
 
+
 void
 orthconn_update_data(OrthConn *orth)
 {
@@ -518,12 +519,12 @@ orthconn_init(OrthConn *orth, Point *startpoint)
   orth->numpoints = 4;
   orth->numorient = orth->numpoints - 1;
 
-  orth->points = g_malloc0(4*sizeof(Point));
+  orth->points = g_new0 (Point, 4);
 
-  orth->orientation = g_malloc0(3*sizeof(Orientation));
+  orth->orientation = g_new0 (Orientation, 3);
 
   orth->numhandles = 3;
-  orth->handles = g_malloc0(3*sizeof(Handle *));
+  orth->handles = g_new0(Handle *, 3);
 
   orth->handles[0] = g_new(Handle, 1);
   setup_endpoint_handle(orth->handles[0], HANDLE_MOVE_STARTPOINT);
@@ -609,16 +610,16 @@ orthconn_copy(OrthConn *from, OrthConn *to)
   to->numpoints = from->numpoints;
   to->numorient = from->numorient;
 
-  to->points = g_malloc0((to->numpoints)*sizeof(Point));
+  to->points = g_new0 (Point, to->numpoints);
 
   for (i=0;i<to->numpoints;i++) {
     to->points[i] = from->points[i];
   }
 
   to->autorouting = from->autorouting;
-  to->orientation = g_malloc0((to->numpoints-1)*sizeof(Orientation));
+  to->orientation = g_new0 (Orientation, to->numpoints - 1);
   to->numhandles = from->numhandles;
-  to->handles = g_malloc0((to->numpoints-1)*sizeof(Handle *));
+  to->handles = g_new0 (Handle *, to->numpoints - 1);
 
   for (i=0;i<to->numpoints-1;i++) {
     to->orientation[i] = from->orientation[i];
@@ -728,7 +729,7 @@ orthconn_load(OrthConn *orth, ObjectNode obj_node,
   object_init(obj, orth->numpoints-1, 0);
 
   data = attribute_first_data(attr);
-  orth->points = g_malloc0((orth->numpoints)*sizeof(Point));
+  orth->points = g_new0 (Point, orth->numpoints);
   for (i=0;i<orth->numpoints;i++) {
     data_point(data, &orth->points[i], ctx);
     data = data_next(data);
@@ -737,7 +738,7 @@ orthconn_load(OrthConn *orth, ObjectNode obj_node,
   attr = object_find_attribute(obj_node, "orth_orient");
 
   data = attribute_first_data(attr);
-  orth->orientation = g_malloc0((orth->numpoints-1)*sizeof(Orientation));
+  orth->orientation = g_new0 (Orientation, orth->numpoints - 1);
   for (i=0;i<orth->numpoints-1;i++) {
     orth->orientation[i] = data_enum(data, ctx);
     data = data_next(data);
@@ -752,21 +753,21 @@ orthconn_load(OrthConn *orth, ObjectNode obj_node,
     orth->autorouting = FALSE;
   }
 
-  orth->handles = g_malloc0((orth->numpoints-1)*sizeof(Handle *));
+  orth->handles = g_new0 (Handle *, orth->numpoints - 1);
 
-  orth->handles[0] = g_new(Handle, 1);
+  orth->handles[0] = g_new (Handle, 1);
   setup_endpoint_handle(orth->handles[0], HANDLE_MOVE_STARTPOINT);
   orth->handles[0]->pos = orth->points[0];
   obj->handles[0] = orth->handles[0];
 
   n = orth->numpoints-2;
-  orth->handles[n] = g_new(Handle, 1);
+  orth->handles[n] = g_new (Handle, 1);
   setup_endpoint_handle(orth->handles[n], HANDLE_MOVE_ENDPOINT);
   orth->handles[n]->pos = orth->points[orth->numpoints-1];
   obj->handles[1] = orth->handles[n];
 
   for (i=1; i<orth->numpoints-2; i++) {
-    orth->handles[i] = g_new(Handle, 1);
+    orth->handles[i] = g_new (Handle, 1);
     setup_midpoint_handle(orth->handles[i]);
     obj->handles[i+1] = orth->handles[i];
   }
@@ -911,18 +912,17 @@ orthconn_set_autorouting (OrthConn *conn, gboolean on)
 static void
 delete_point(OrthConn *orth, int pos)
 {
-  int i;
-
   orth->numpoints--;
   orth->numorient = orth->numpoints - 1;
 
-  for (i=pos;i<orth->numpoints;i++) {
+  for (int i = pos; i < orth->numpoints; i++) {
     orth->points[i] = orth->points[i+1];
   }
 
-  orth->points = g_realloc(orth->points, orth->numpoints*sizeof(Point));
+  orth->points = g_renew (Point, orth->points, orth->numpoints);
 }
 
+
 /* Make sure numpoints have been decreased before calling this function.
  * ie. call delete_point first.
  */
@@ -939,10 +939,10 @@ remove_handle(OrthConn *orth, int segment)
     orth->orientation[i] = orth->orientation[i+1];
   }
 
-  orth->orientation = g_realloc(orth->orientation,
-                             (orth->numpoints-1)*sizeof(Orientation));
-  orth->handles = g_realloc(orth->handles,
-                         (orth->numpoints-1)*sizeof(Handle *));
+  orth->orientation = g_renew (Orientation,
+                               orth->orientation,
+                               orth->numpoints - 1);
+  orth->handles = g_renew (Handle *, orth->handles, orth->numpoints - 1);
 
   object_remove_handle(&orth->object, handle);
   orth->numhandles = orth->numpoints-1;
@@ -950,37 +950,38 @@ remove_handle(OrthConn *orth, int segment)
 
 
 static void
-add_point(OrthConn *orth, int pos, Point *point)
+add_point (OrthConn *orth, int pos, Point *point)
 {
-  int i;
-
   orth->numpoints++;
   orth->numorient = orth->numpoints-1;
 
-  orth->points = g_realloc(orth->points, orth->numpoints*sizeof(Point));
-  for (i=orth->numpoints-1;i>pos;i--) {
+  orth->points = g_renew (Point, orth->points, orth->numpoints);
+  for (int i = orth->numpoints - 1; i > pos; i--) {
     orth->points[i] = orth->points[i-1];
   }
   orth->points[pos] = *point;
 }
 
+
 /* Make sure numpoints have been increased before calling this function.
  * ie. call add_point first.
  */
 static void
-insert_handle(OrthConn *orth, int segment,
-             Handle *handle, Orientation orient)
+insert_handle (OrthConn    *orth,
+               int          segment,
+               Handle      *handle,
+               Orientation  orient)
 {
-  int i;
+  orth->orientation = g_renew (Orientation,
+                               orth->orientation,
+                               orth->numpoints - 1);
+  orth->handles = g_renew (Handle *, orth->handles, orth->numpoints - 1);
 
-  orth->orientation = g_realloc(orth->orientation,
-                             (orth->numpoints-1)*sizeof(Orientation));
-  orth->handles = g_realloc(orth->handles,
-                         (orth->numpoints-1)*sizeof(Handle *));
-  for (i=orth->numpoints-2;i>segment;i--) {
+  for (int i = orth->numpoints - 2; i > segment; i--) {
     orth->handles[i] = orth->handles[i-1];
     orth->orientation[i] = orth->orientation[i-1];
   }
+
   orth->handles[segment] = handle;
   orth->orientation[segment] = orient;
 
diff --git a/lib/poly_conn.c b/lib/poly_conn.c
index 5f65f0155..bde65b38a 100644
--- a/lib/poly_conn.c
+++ b/lib/poly_conn.c
@@ -217,7 +217,7 @@ add_handle(PolyConn *poly, int pos, Point *point, Handle *handle)
   DiaObject *obj;
 
   poly->numpoints++;
-  poly->points = g_realloc(poly->points, poly->numpoints*sizeof(Point));
+  poly->points = g_renew (Point, poly->points, poly->numpoints);
 
   for (i=poly->numpoints-1; i > pos; i--) {
     poly->points[i] = poly->points[i-1];
@@ -259,7 +259,7 @@ remove_handle(PolyConn *poly, int pos)
   for (i=pos; i < poly->numpoints; i++) {
     poly->points[i] = poly->points[i+1];
   }
-  poly->points = g_realloc(poly->points, poly->numpoints*sizeof(Point));
+  poly->points = g_renew (Point, poly->points, poly->numpoints);
 
   old_handle = obj->handles[pos];
   object_remove_handle(&poly->object, old_handle);
@@ -281,7 +281,7 @@ polyconn_add_point (PolyConn *poly, int segment, Point *point)
     realpoint = *point;
   }
 
-  new_handle = g_malloc(sizeof(Handle));
+  new_handle = g_new0 (Handle, 1);
   setup_handle(new_handle, PC_HANDLE_CORNER);
   add_handle(poly, segment+1, &realpoint, new_handle);
   return polyconn_create_change(poly, TYPE_ADD_POINT,
@@ -322,11 +322,10 @@ polyconn_update_data(PolyConn *poly)
   if (poly->numpoints != obj->num_handles) {
     g_assert(0 == obj->num_connections);
 
-    obj->handles = g_realloc(obj->handles,
-                             poly->numpoints*sizeof(Handle *));
+    obj->handles = g_renew (Handle *, obj->handles, poly->numpoints);
     obj->num_handles = poly->numpoints;
     for (i=0;i<poly->numpoints;i++) {
-      obj->handles[i] = g_malloc(sizeof(Handle));
+      obj->handles[i] = g_new0 (Handle, 1);
       if (0 == i)
         setup_handle(obj->handles[i], PC_HANDLE_START);
       else if (i == poly->numpoints-1)
@@ -365,10 +364,10 @@ polyconn_init(PolyConn *poly, int num_points)
 
   poly->numpoints = num_points;
 
-  poly->points = g_malloc(num_points*sizeof(Point));
+  poly->points = g_new0 (Point, num_points);
 
   for (i=0;i<num_points;i++) {
-    obj->handles[i] = g_malloc(sizeof(Handle));
+    obj->handles[i] = g_new0 (Handle, 1);
     if (0 == i)
       setup_handle(obj->handles[i], PC_HANDLE_START);
     else if (i == num_points-1)
@@ -390,41 +389,44 @@ polyconn_set_points(PolyConn *poly, int num_points, Point *points)
 
   g_clear_pointer (&poly->points, g_free);
 
-  poly->points = g_malloc((poly->numpoints)*sizeof(Point));
+  poly->points = g_new0 (Point, poly->numpoints);
 
   for (i=0;i<poly->numpoints;i++) {
     poly->points[i] = points[i];
   }
 }
 
+
 void
-polyconn_copy(PolyConn *from, PolyConn *to)
+polyconn_copy (PolyConn *from, PolyConn *to)
 {
-  int i;
   DiaObject *toobj, *fromobj;
 
   toobj = &to->object;
   fromobj = &from->object;
 
-  object_copy(fromobj, toobj);
+  object_copy (fromobj, toobj);
 
-  to->object.handles[0] = g_new(Handle,1);
+  to->object.handles[0] = g_new0 (Handle,1);
   *to->object.handles[0] = *from->object.handles[0];
 
-  for (i=1;i<toobj->num_handles-1;i++) {
-    to->object.handles[i] = g_malloc(sizeof(Handle));
-    setup_handle(to->object.handles[i], PC_HANDLE_CORNER);
+  for (int i = 1; i < toobj->num_handles - 1; i++) {
+    to->object.handles[i] = g_new0 (Handle, 1);
+    setup_handle (to->object.handles[i], PC_HANDLE_CORNER);
   }
 
-  to->object.handles[toobj->num_handles-1] = g_new(Handle,1);
+  to->object.handles[toobj->num_handles-1] = g_new0 (Handle,1);
   *to->object.handles[toobj->num_handles-1] =
       *from->object.handles[toobj->num_handles-1];
-  polyconn_set_points(to, from->numpoints, from->points);
+  polyconn_set_points (to, from->numpoints, from->points);
 
-  memcpy(&to->extra_spacing,&from->extra_spacing,sizeof(to->extra_spacing));
-  polyconn_update_data(to);
+  memcpy (&to->extra_spacing,
+          &from->extra_spacing,
+          sizeof(to->extra_spacing));
+  polyconn_update_data (to);
 }
 
+
 void
 polyconn_destroy (PolyConn *poly)
 {
@@ -464,51 +466,52 @@ polyconn_save(PolyConn *poly, ObjectNode obj_node, DiaContext *ctx)
   }
 }
 
+
 void
-polyconn_load(PolyConn *poly, ObjectNode obj_node, DiaContext *ctx) /* NOTE: Does object_init() */
+polyconn_load (PolyConn *poly, ObjectNode obj_node, DiaContext *ctx) /* NOTE: Does object_init() */
 {
-  int i;
   AttributeNode attr;
   DataNode data;
 
   DiaObject *obj = &poly->object;
 
-  object_load(obj, obj_node, ctx);
+  object_load (obj, obj_node, ctx);
 
-  attr = object_find_attribute(obj_node, "poly_points");
+  attr = object_find_attribute (obj_node, "poly_points");
 
-  if (attr != NULL)
-    poly->numpoints = attribute_num_data(attr);
-  else
+  if (attr != NULL) {
+    poly->numpoints = attribute_num_data (attr);
+  } else {
     poly->numpoints = 0;
+  }
 
-  object_init(obj, poly->numpoints, 0);
+  object_init (obj, poly->numpoints, 0);
 
-  data = attribute_first_data(attr);
-  poly->points = g_malloc(poly->numpoints*sizeof(Point));
-  for (i=0;i<poly->numpoints;i++) {
-    data_point(data, &poly->points[i], ctx);
-    data = data_next(data);
+  data = attribute_first_data (attr);
+  poly->points = g_new0 (Point, poly->numpoints);
+  for (int i = 0; i < poly->numpoints; i++) {
+    data_point (data, &poly->points[i], ctx);
+    data = data_next (data);
   }
 
-  obj->handles[0] = g_malloc(sizeof(Handle));
+  obj->handles[0] = g_new0 (Handle, 1);
   obj->handles[0]->connect_type = HANDLE_CONNECTABLE;
   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] = g_new0 (Handle, 1);
   obj->handles[poly->numpoints-1]->connect_type = HANDLE_CONNECTABLE;
   obj->handles[poly->numpoints-1]->connected_to = NULL;
   obj->handles[poly->numpoints-1]->type = HANDLE_MAJOR_CONTROL;
   obj->handles[poly->numpoints-1]->id = HANDLE_MOVE_ENDPOINT;
 
-  for (i=1;i<poly->numpoints-1;i++) {
-    obj->handles[i] = g_malloc(sizeof(Handle));
-    setup_handle(obj->handles[i], PC_HANDLE_CORNER);
+  for (int i = 1; i < poly->numpoints - 1; i++) {
+    obj->handles[i] = g_new0 (Handle, 1);
+    setup_handle (obj->handles[i], PC_HANDLE_CORNER);
   }
 
-  polyconn_update_data(poly);
+  polyconn_update_data (poly);
 }
 
 
diff --git a/lib/polyshape.c b/lib/polyshape.c
index b1a703ad7..a04696ee3 100644
--- a/lib/polyshape.c
+++ b/lib/polyshape.c
@@ -167,29 +167,35 @@ polyshape_distance_from(PolyShape *poly, Point *point, real line_width)
                                line_width, point);
 }
 
+
 static void
-add_handle(PolyShape *poly, int pos, Point *point, Handle *handle,
-          ConnectionPoint *cp1, ConnectionPoint *cp2)
+add_handle (PolyShape       *poly,
+            int              pos,
+            Point           *point,
+            Handle          *handle,
+            ConnectionPoint *cp1,
+            ConnectionPoint *cp2)
 {
-  int i;
   DiaObject *obj = &poly->object;
 
   poly->numpoints++;
-  poly->points = g_realloc(poly->points, poly->numpoints*sizeof(Point));
+  poly->points = g_renew (Point, poly->points, poly->numpoints);
 
-  for (i=poly->numpoints-1; i > pos; i--) {
+  for (int i = poly->numpoints - 1; i > pos; i--) {
     poly->points[i] = poly->points[i-1];
   }
+
   poly->points[pos] = *point;
-  object_add_handle_at(obj, handle, pos);
-  object_add_connectionpoint_at(obj, cp1, 2*pos);
-  object_add_connectionpoint_at(obj, cp2, 2*pos+1);
+
+  object_add_handle_at (obj, handle, pos);
+  object_add_connectionpoint_at (obj, cp1, 2 * pos);
+  object_add_connectionpoint_at (obj, cp2, 2 * pos + 1);
 }
 
+
 static void
-remove_handle(PolyShape *poly, int pos)
+remove_handle (PolyShape *poly, int pos)
 {
-  int i;
   DiaObject *obj;
   Handle *old_handle;
   ConnectionPoint *old_cp1, *old_cp2;
@@ -198,17 +204,19 @@ remove_handle(PolyShape *poly, int pos)
 
   /* delete the points */
   poly->numpoints--;
-  for (i=pos; i < poly->numpoints; i++) {
+  for (int i = pos; i < poly->numpoints; i++) {
     poly->points[i] = poly->points[i+1];
   }
-  poly->points = g_realloc(poly->points, poly->numpoints*sizeof(Point));
+
+  poly->points = g_renew (Point, poly->points, poly->numpoints);
 
   old_handle = obj->handles[pos];
   old_cp1 = obj->connections[2*pos];
   old_cp2 = obj->connections[2*pos+1];
-  object_remove_handle(&poly->object, old_handle);
-  object_remove_connectionpoint(obj, old_cp1);
-  object_remove_connectionpoint(obj, old_cp2);
+
+  object_remove_handle (&poly->object, old_handle);
+  object_remove_connectionpoint (obj, old_cp1);
+  object_remove_connectionpoint (obj, old_cp2);
 }
 
 
@@ -322,8 +330,9 @@ find_tip_directions(Point prev, Point this, Point next)
   return dirs;
 }
 
+
 void
-polyshape_update_data(PolyShape *poly)
+polyshape_update_data (PolyShape *poly)
 {
   Point next;
   int i;
@@ -335,16 +344,17 @@ polyshape_update_data(PolyShape *poly)
       NUM_CONNECTIONS(poly) != obj->num_connections) {
     object_unconnect_all(obj); /* too drastic ? */
 
-    obj->handles = g_realloc(obj->handles,
-                             poly->numpoints*sizeof(Handle *));
+    obj->handles = g_renew (Handle *, obj->handles, poly->numpoints);
     obj->num_handles = poly->numpoints;
-    for (i=0;i<poly->numpoints;i++) {
-      obj->handles[i] = g_new(Handle, 1);
-      setup_handle(obj->handles[i]);
+    for (i = 0; i < poly->numpoints; i++) {
+      obj->handles[i] = g_new0 (Handle, 1);
+      setup_handle (obj->handles[i]);
     }
 
-    obj->connections = g_realloc(obj->connections,
-                                 NUM_CONNECTIONS(poly) * sizeof(ConnectionPoint *));
+    obj->connections = g_renew (ConnectionPoint *,
+                                obj->connections,
+                                NUM_CONNECTIONS (poly));
+
     for (i = 0; i < NUM_CONNECTIONS(poly); i++) {
       obj->connections[i] = g_new0(ConnectionPoint, 1);
       obj->connections[i]->object = obj;
@@ -420,7 +430,7 @@ polyshape_init(PolyShape *poly, int num_points)
 
   poly->numpoints = num_points;
 
-  poly->points = g_malloc(num_points*sizeof(Point));
+  poly->points = g_new0 (Point, num_points);
 
   for (i = 0; i < num_points; i++) {
     obj->handles[i] = g_new(Handle, 1);
diff --git a/lib/text.c b/lib/text.c
index f0c894a42..837a19f81 100644
--- a/lib/text.c
+++ b/lib/text.c
@@ -143,7 +143,7 @@ text_delete_line (Text *text, int line_no)
   }
 
   text->numlines -= 1;
-  text->lines = g_realloc (text->lines, sizeof (TextLine *) * text->numlines);
+  text->lines = g_renew (TextLine *, text->lines, text->numlines);
 }
 
 
@@ -160,7 +160,7 @@ static void
 text_insert_line (Text *text, int line_no)
 {
   text->numlines += 1;
-  text->lines = g_realloc (text->lines, sizeof (char *) * text->numlines);
+  text->lines = g_renew (TextLine *, text->lines, text->numlines);
 
   for (int i = text->numlines - 1; i > line_no; i--) {
     text->lines[i] = text->lines[i - 1];
@@ -594,7 +594,7 @@ text_get_string_copy (const Text *text)
     num += strlen (text_get_line (text, i)) + 1;
   }
 
-  str = g_malloc0 (num);
+  str = g_new0 (char, num);
 
   for (int i = 0; i < text->numlines; i++) {
     strcat (str, text_get_line (text, i));
diff --git a/objects/AADL/aadlbox.c b/objects/AADL/aadlbox.c
index 059687cd4..8e5e4136a 100644
--- a/objects/AADL/aadlbox.c
+++ b/objects/AADL/aadlbox.c
@@ -496,13 +496,12 @@ aadlbox_add_port(Aadlbox *aadlbox, const Point *p, Aadlport *port)
 
   aadlbox->num_ports++;
 
-  if (aadlbox->ports == NULL)
-    aadlbox->ports = g_malloc(sizeof(Aadlport*)*aadlbox->num_ports);
-
-  else
+  if (aadlbox->ports == NULL) {
+    aadlbox->ports = g_new0 (Aadlport *, aadlbox->num_ports);
+  } else {
     /* Allocate more ports */
-    aadlbox->ports = g_realloc(aadlbox->ports,
-                                      sizeof(Aadlport*)*aadlbox->num_ports);
+    aadlbox->ports = g_renew (Aadlport *, aadlbox->ports, aadlbox->num_ports);
+  }
 
   i = aadlbox->num_ports - 1;
 
@@ -539,8 +538,7 @@ aadlbox_remove_port(Aadlbox *aadlbox, Aadlport *port)
       object_remove_connectionpoint(&aadlbox->element.object, &port->out);
 
       aadlbox->num_ports--;
-      aadlbox->ports = g_realloc(aadlbox->ports,
-                              sizeof(Aadlport *)*aadlbox->num_ports);
+      aadlbox->ports = g_renew (Aadlport *, aadlbox->ports, aadlbox->num_ports);
       break;
     }
   }
@@ -619,14 +617,14 @@ aadlbox_add_connection(Aadlbox *aadlbox, const Point *p, ConnectionPoint *connec
 
   aadlbox->num_connections++;
 
-  if (aadlbox->connections == NULL)
-    aadlbox->connections =
-      g_malloc(sizeof(ConnectionPoint*)*aadlbox->num_connections);
-
-  else
+  if (aadlbox->connections == NULL) {
+    aadlbox->connections = g_new0 (ConnectionPoint *, aadlbox->num_connections);
+  } else {
     /* Allocate more connections */
-    aadlbox->connections = g_realloc(aadlbox->connections,
-                           sizeof(ConnectionPoint*)*aadlbox->num_connections);
+    aadlbox->connections = g_renew (ConnectionPoint *,
+                                    aadlbox->connections,
+                                    aadlbox->num_connections);
+  }
 
   i = aadlbox->num_connections - 1;
 
@@ -652,8 +650,9 @@ aadlbox_remove_connection(Aadlbox *aadlbox, ConnectionPoint *connection)
       object_remove_connectionpoint(&aadlbox->element.object, connection);
 
       aadlbox->num_connections--;
-      aadlbox->connections = g_realloc(aadlbox->connections,
-                          sizeof(ConnectionPoint *)*aadlbox->num_connections);
+      aadlbox->connections = g_renew (ConnectionPoint *,
+                                      aadlbox->connections,
+                                      aadlbox->num_connections);
       break;
     }
   }
@@ -897,7 +896,7 @@ DiaObject *aadlbox_create(Point *startpoint, void *user_data,
   Point p;
   DiaFont *font;
 
-  aadlbox = g_malloc0(sizeof(Aadlbox));
+  aadlbox = g_new0 (Aadlbox, 1);
   elem = &aadlbox->element;
   obj = &elem->object;
 
diff --git a/objects/AADL/edit_port_declaration.c b/objects/AADL/edit_port_declaration.c
index 045255683..e3ddce7c7 100644
--- a/objects/AADL/edit_port_declaration.c
+++ b/objects/AADL/edit_port_declaration.c
@@ -96,15 +96,17 @@ dia_aadl_edit_port_declaration_object_change_free (DiaObjectChange *self)
  ***********************************************/
 
 static GtkWidget *entry;
-static gchar *text;
+static char *text = NULL;
+
 
 static void
 save_text (void)
 {
-  text = (gchar *) g_malloc (strlen(gtk_entry_get_text (GTK_ENTRY (entry)))+1);
-  strcpy(text, gtk_entry_get_text (GTK_ENTRY (entry)));
+  g_clear_pointer (&text, g_free);
+  text = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
 }
 
+
 static gboolean delete_event ( GtkWidget *widget,
                               GdkEvent  *event,
                               gpointer   data )
diff --git a/objects/Database/compound.c b/objects/Database/compound.c
index ef3cbda71..5c7a479f9 100644
--- a/objects/Database/compound.c
+++ b/objects/Database/compound.c
@@ -872,21 +872,21 @@ static void compound_update_object (Compound * comp)
 #endif
 }
 
+
 /**
  * Add or remove handles, so that comp->object.num_handles will equal to
  * the specified value. When there have been no changes done 0 is
  * returned, otherwise the number of handles removed (negative value) or
  * the number of added handles (positive value) will be returned.
  */
-static gint
+static int
 adjust_handle_count_to (Compound * comp, gint to)
 {
   DiaObject * obj = &comp->object;
-  gint old_count = obj->num_handles;
-  gint new_count = to;
+  int old_count = obj->num_handles;
+  int new_count = to;
   Handle * h;
-  gint i;
-  gint diff = 0;
+  int diff = 0;
 
   /* we require to have always at least two arms! */
   g_assert (new_count >= 3);
@@ -894,31 +894,34 @@ adjust_handle_count_to (Compound * comp, gint to)
   if (new_count == old_count)
     return diff; /* every thing is ok */
 
-  obj->handles = g_realloc (obj->handles, new_count * sizeof(Handle *));
+  obj->handles = g_renew (Handle *, obj->handles, new_count);
   obj->num_handles = new_count;
   comp->num_arms = new_count-1;
 
-  if (new_count < old_count) /* removing */
-    {
-      for (i = new_count; i < old_count; i++)
-        object_unconnect (obj, &comp->handles[i]);
-      comp->handles = g_realloc (comp->handles, sizeof(Handle) * new_count);
+  if (new_count < old_count) {
+    /* removing */
+    for (int i = new_count; i < old_count; i++) {
+      object_unconnect (obj, &comp->handles[i]);
     }
-  else /* adding */
-    {
-      comp->handles = g_realloc (comp->handles, sizeof(Handle) * new_count);
-      for (i = old_count; i < new_count; i++)
-        {
-          h = &comp->handles[i];
-          setup_handle (h, HANDLE_ARM,
-                        HANDLE_MINOR_CONTROL, HANDLE_CONNECTABLE_NOBREAK);
-        }
+    comp->handles = g_renew (Handle, comp->handles, new_count);
+  } else {
+    /* adding */
+    comp->handles = g_renew (Handle, comp->handles, new_count);
+    for (int i = old_count; i < new_count; i++) {
+      h = &comp->handles[i];
+      setup_handle (h, HANDLE_ARM,
+                    HANDLE_MINOR_CONTROL, HANDLE_CONNECTABLE_NOBREAK);
     }
-  for (i = 0; i < new_count; i++)
+  }
+
+  for (int i = 0; i < new_count; i++) {
     obj->handles[i] = &comp->handles[i];
+  }
+
   return new_count - old_count;
 }
 
+
 static void
 setup_mount_point (ConnectionPoint * mp, DiaObject * obj, Point * pos)
 {
diff --git a/objects/Database/table.c b/objects/Database/table.c
index 90cc66c89..9fa4a4657 100644
--- a/objects/Database/table.c
+++ b/objects/Database/table.c
@@ -411,7 +411,7 @@ table_create (Point * startpoint,
   DiaObject *obj;
   gint i;
 
-  table = g_malloc0 (sizeof (Table));
+  table = g_new0 (Table, 1);
   elem = &table->element;
   obj = &elem->object;
 
@@ -1140,7 +1140,7 @@ create_documentation_tag (char     *comment,
   int   WorkingWrapPoint = (TagLength<WrapPoint) ? WrapPoint : ((TagLength<=0)?1:TagLength);
   int   RawLength        = TagLength + strlen(comment) + (tagging?1:0);
   int   MaxCookedLength  = RawLength + RawLength/WorkingWrapPoint;
-  char *WrappedComment   = g_malloc0(MaxCookedLength+1);
+  char *WrappedComment   = g_new0 (char, MaxCookedLength + 1);
   int   AvailSpace       = WorkingWrapPoint - TagLength;
   char *Scan;
   char *BreakCandidate;
@@ -1344,13 +1344,14 @@ table_update_connectionpoints (Table * table)
   obj = &table->element.object;
   num_attrs = g_list_length (table->attributes);
   num_connections = TABLE_CONNECTIONPOINTS + 2*num_attrs;
-  if (num_connections != obj->num_connections)
-    {
-      obj->num_connections = num_connections;
-      obj->connections =
-        g_realloc (obj->connections,
-                   num_connections * sizeof (ConnectionPoint *));
-    }
+
+  if (num_connections != obj->num_connections) {
+    obj->num_connections = num_connections;
+    obj->connections = g_renew (ConnectionPoint *,
+                                obj->connections,
+                                num_connections);
+  }
+
   list = table->attributes;
   index = TABLE_CONNECTIONPOINTS;
   while (list != NULL)
diff --git a/objects/ER/attribute.c b/objects/ER/attribute.c
index a50f0fb05..4e4adc0d8 100644
--- a/objects/ER/attribute.c
+++ b/objects/ER/attribute.c
@@ -408,7 +408,7 @@ attribute_create(Point *startpoint,
   DiaObject *obj;
   int i;
 
-  attribute = g_malloc0(sizeof(Attribute));
+  attribute = g_new0 (Attribute, 1);
   elem = &attribute->element;
   obj = &elem->object;
 
@@ -472,7 +472,7 @@ attribute_copy(Attribute *attribute)
 
   elem = &attribute->element;
 
-  newattribute = g_malloc0(sizeof(Attribute));
+  newattribute = g_new0 (Attribute, 1);
   newelem = &newattribute->element;
   newobj = &newelem->object;
 
@@ -541,7 +541,7 @@ attribute_load(ObjectNode obj_node, int version,DiaContext *ctx)
   int i;
   AttributeNode attr;
 
-  attribute = g_malloc0(sizeof(Attribute));
+  attribute = g_new0 (Attribute, 1);
   elem = &attribute->element;
   obj = &elem->object;
 
diff --git a/objects/ER/entity.c b/objects/ER/entity.c
index 3c0390576..f17cf3893 100644
--- a/objects/ER/entity.c
+++ b/objects/ER/entity.c
@@ -375,7 +375,7 @@ entity_create(Point *startpoint,
   DiaObject *obj;
   int i;
 
-  entity = g_malloc0(sizeof(Entity));
+  entity = g_new0 (Entity, 1);
   elem = &entity->element;
   obj = &elem->object;
 
@@ -439,7 +439,7 @@ entity_copy(Entity *entity)
 
   elem = &entity->element;
 
-  newentity = g_malloc0(sizeof(Entity));
+  newentity = g_new0 (Entity, 1);
   newelem = &newentity->element;
   newobj = &newelem->object;
 
@@ -499,7 +499,7 @@ entity_load(ObjectNode obj_node, int version,DiaContext *ctx)
   int i;
   AttributeNode attr;
 
-  entity = g_malloc0(sizeof(Entity));
+  entity = g_new0 (Entity, 1);
   elem = &entity->element;
   obj = &elem->object;
 
diff --git a/objects/ER/participation.c b/objects/ER/participation.c
index 27fe2558e..03a2d6068 100644
--- a/objects/ER/participation.c
+++ b/objects/ER/participation.c
@@ -312,7 +312,7 @@ participation_create(Point *startpoint,
   OrthConn *orth;
   DiaObject *obj;
 
-  participation = g_malloc0(sizeof(Participation));
+  participation = g_new0 (Participation, 1);
   orth = &participation->orth;
   obj = &orth->object;
 
@@ -340,7 +340,7 @@ participation_copy(Participation *participation)
 
   orth = &participation->orth;
 
-  newparticipation = g_malloc0(sizeof(Participation));
+  newparticipation = g_new0 (Participation, 1);
   neworth = &newparticipation->orth;
 
   orthconn_copy(orth, neworth);
diff --git a/objects/ER/relationship.c b/objects/ER/relationship.c
index 2066324eb..54f9863d7 100644
--- a/objects/ER/relationship.c
+++ b/objects/ER/relationship.c
@@ -525,7 +525,7 @@ relationship_copy (Relationship *relationship)
 
   elem = &relationship->element;
 
-  newrelationship = g_malloc0 (sizeof (Relationship));
+  newrelationship = g_new0 (Relationship, 1);
   newelem = &newrelationship->element;
   newobj = &newelem->object;
 
@@ -599,7 +599,7 @@ relationship_load (ObjectNode obj_node, int version, DiaContext *ctx)
   int i;
   AttributeNode attr;
 
-  relationship = g_malloc0 (sizeof (Relationship));
+  relationship = g_new0 (Relationship, 1);
   elem = &relationship->element;
   obj = &elem->object;
 
diff --git a/objects/FS/flow-ortho.c b/objects/FS/flow-ortho.c
index b6a1ae1cd..6530a234a 100644
--- a/objects/FS/flow-ortho.c
+++ b/objects/FS/flow-ortho.c
@@ -518,7 +518,7 @@ orthflow_copy(Orthflow *orthflow)
 
   orth = &orthflow->orth;
 
-  neworthflow = g_malloc0(sizeof(Orthflow));
+  neworthflow = g_new0 (Orthflow, 1);
   neworth = &neworthflow->orth;
   newobj = &neworth->object;
 
@@ -594,7 +594,7 @@ orthflow_load(ObjectNode obj_node, int version, DiaContext *ctx)
   DiaObject *obj;
   PolyBBExtras *extra;
 
-  orthflow = g_malloc0(sizeof(Orthflow));
+  orthflow = g_new0 (Orthflow, 1);
 
   orth = &orthflow->orth;
   obj = &orth->object;
diff --git a/objects/FS/flow.c b/objects/FS/flow.c
index ab239dbbf..6beca65a6 100644
--- a/objects/FS/flow.c
+++ b/objects/FS/flow.c
@@ -378,7 +378,7 @@ flow_create(Point *startpoint,
   Point n ;
   DiaFont *font;
 
-  flow = g_malloc0(sizeof(Flow));
+  flow = g_new0 (Flow, 1);
 
   conn = &flow->connection;
   conn->endpoints[0] = *startpoint;
@@ -450,7 +450,7 @@ flow_copy(Flow *flow)
 
   conn = &flow->connection;
 
-  newflow = g_malloc0(sizeof(Flow));
+  newflow = g_new0 (Flow, 1);
   newconn = &newflow->connection;
   newobj = &newconn->object;
 
@@ -531,7 +531,7 @@ flow_load(ObjectNode obj_node, int version, DiaContext *ctx)
   DiaObject *obj;
   LineBBExtras *extra;
 
-  flow = g_malloc0(sizeof(Flow));
+  flow = g_new0 (Flow, 1);
 
   conn = &flow->connection;
   obj = &conn->object;
diff --git a/objects/FS/function.c b/objects/FS/function.c
index 8bfddefa3..3ca07fec0 100644
--- a/objects/FS/function.c
+++ b/objects/FS/function.c
@@ -472,7 +472,7 @@ function_create(Point *startpoint,
   DiaFont *font;
   int i;
 
-  pkg = g_malloc0(sizeof(Function));
+  pkg = g_new0 (Function, 1);
   elem = &pkg->element;
   obj = &elem->object;
 
@@ -534,7 +534,7 @@ function_copy(Function *pkg)
 
   elem = &pkg->element;
 
-  newpkg = g_malloc0(sizeof(Function));
+  newpkg = g_new0 (Function, 1);
   newelem = &newpkg->element;
   newobj = &newelem->object;
 
@@ -584,7 +584,7 @@ function_load(ObjectNode obj_node, int version, DiaContext *ctx)
   DiaObject *obj;
   int i;
 
-  pkg = g_malloc0(sizeof(Function));
+  pkg = g_new0 (Function, 1);
   elem = &pkg->element;
   obj = &elem->object;
 
@@ -639,8 +639,8 @@ function_insert_word (Function *func, const char *word, gboolean newline)
 {
   DiaObjectChange* change = function_create_change (func, TEXT_EDIT);
   char *old_chars = text_get_string_copy (func->text);
-  char *new_chars = g_malloc (strlen (old_chars) + strlen (word)
-                                      + (newline ? 2 : 1));
+  char *new_chars = g_new0 (char,
+                            strlen (old_chars) + strlen (word) + (newline ? 2 : 1));
   sprintf (new_chars, newline ? "%s\n%s" : "%s%s", old_chars, word);
   text_set_string (func->text, new_chars);
   g_clear_pointer (&new_chars, g_free);
@@ -1243,46 +1243,47 @@ function_count_submenu_items( struct _IndentedMenus* itemPtr )
   return cnt ;
 }
 
-static DiaMenu*
-function_get_object_menu( Function* func, Point* clickedpoint )
+
+static DiaMenu *
+function_get_object_menu (Function *func, Point *clickedpoint)
 {
-  if ( ! function_menu ) {
-  int i ;
-    int curDepth = 0 ;
-    DiaMenu* curMenu[ FS_SUBMENU_MAXINDENT ] ;
-    int curitem[ FS_SUBMENU_MAXINDENT ] ;
-
-    curitem[0] = 0 ;
-    curMenu[0] = g_malloc( sizeof( DiaMenu ) ) ;
-    curMenu[0]->title = "Function" ;
-    curMenu[0]->num_items = function_count_submenu_items( &(fmenu[0]) ) ;
-    curMenu[0]->items = g_malloc( curMenu[0]->num_items * sizeof(DiaMenuItem) );
-    curMenu[0]->app_data = NULL ;
-    for (i = 0 ; fmenu[i].depth >= 0; i++) {
-      if ( fmenu[i].depth > curDepth ) {
-       curDepth++ ;
-       curMenu[curDepth] = g_malloc( sizeof( DiaMenu ) ) ;
-       curMenu[curDepth]->title = NULL ;
-       curMenu[curDepth]->app_data = NULL ;
-       curMenu[curDepth]->num_items = function_count_submenu_items(&fmenu[i]);
-       curMenu[curDepth]->items = g_malloc( curMenu[curDepth]->num_items *
-                                 sizeof(DiaMenuItem) ) ;
-       /* Point this menu's parent to this new structure */
-       curMenu[curDepth-1]->items[curitem[curDepth-1]-1].callback = NULL ;
-       curMenu[curDepth-1]->items[curitem[curDepth-1]-1].callback_data =
-               curMenu[curDepth] ;
-       curitem[ curDepth ] = 0 ;
-      } else if ( fmenu[i].depth < curDepth ) {
-       curDepth=fmenu[i].depth ;
+  if (!function_menu) {
+    int curDepth = 0;
+    DiaMenu *curMenu[FS_SUBMENU_MAXINDENT];
+    int curitem[FS_SUBMENU_MAXINDENT];
+
+    curitem[0] = 0;
+    curMenu[0] = g_new0 (DiaMenu, 1);
+    curMenu[0]->title = "Function";
+    curMenu[0]->num_items = function_count_submenu_items (&(fmenu[0]));
+    curMenu[0]->items = g_new0 (DiaMenuItem, curMenu[0]->num_items);
+    curMenu[0]->app_data = NULL;
+
+    for (int i = 0; fmenu[i].depth >= 0; i++) {
+      if (fmenu[i].depth > curDepth) {
+        curDepth++;
+        curMenu[curDepth] = g_new0 (DiaMenu, 1);
+        curMenu[curDepth]->title = NULL;
+        curMenu[curDepth]->app_data = NULL;
+        curMenu[curDepth]->num_items = function_count_submenu_items (&fmenu[i]);
+        curMenu[curDepth]->items = g_new0 (DiaMenuItem, curMenu[curDepth]->num_items);
+        /* Point this menu's parent to this new structure */
+        curMenu[curDepth-1]->items[curitem[curDepth-1]-1].callback = NULL ;
+        curMenu[curDepth-1]->items[curitem[curDepth-1]-1].callback_data =
+          curMenu[curDepth];
+        curitem[curDepth] = 0 ;
+      } else if (fmenu[i].depth < curDepth) {
+        curDepth = fmenu[i].depth;
+      }
+
+      curMenu[curDepth]->items[curitem[curDepth]].text = fmenu[i].name;
+      curMenu[curDepth]->items[curitem[curDepth]].callback = fmenu[i].func;
+      curMenu[curDepth]->items[curitem[curDepth]].callback_data = fmenu[i].name;
+      curMenu[curDepth]->items[curitem[curDepth]].active = 1;
+      curitem[curDepth]++;
     }
 
-      curMenu[curDepth]->items[curitem[curDepth]].text = fmenu[i].name ;
-      curMenu[curDepth]->items[curitem[curDepth]].callback = fmenu[i].func ;
-      curMenu[curDepth]->items[curitem[curDepth]].callback_data = fmenu[i].name;
-      curMenu[curDepth]->items[curitem[curDepth]].active = 1 ;
-      curitem[curDepth]++ ;
-  }
-    function_menu = curMenu[0] ;
+    function_menu = curMenu[0];
   }
-  return function_menu ;
+  return function_menu;
 }
diff --git a/objects/GRAFCET/action.c b/objects/GRAFCET/action.c
index 6f074ad64..56ee610d0 100644
--- a/objects/GRAFCET/action.c
+++ b/objects/GRAFCET/action.c
@@ -395,7 +395,7 @@ action_create(Point *startpoint,
 
   DiaFont* action_font;
 
-  action = g_malloc0(sizeof(Action));
+  action = g_new0 (Action, 1);
   conn = &action->connection;
   obj = &conn->object;
   extra = &conn->extra_spacing;
diff --git a/objects/GRAFCET/condition.c b/objects/GRAFCET/condition.c
index d001041ec..1c212066c 100644
--- a/objects/GRAFCET/condition.c
+++ b/objects/GRAFCET/condition.c
@@ -388,7 +388,7 @@ condition_create(Point *startpoint,
   real default_fontheight;
   Color fg_color;
 
-  condition = g_malloc0(sizeof(Condition));
+  condition = g_new0 (Condition, 1);
   conn = &condition->connection;
   obj = &conn->object;
   extra = &conn->extra_spacing;
diff --git a/objects/GRAFCET/vector.c b/objects/GRAFCET/vector.c
index c3c57fb02..9472641bb 100644
--- a/objects/GRAFCET/vector.c
+++ b/objects/GRAFCET/vector.c
@@ -253,7 +253,7 @@ arc_create(Point *startpoint,
   OrthConn *orth;
   DiaObject *obj;
 
-  arc = g_malloc0(sizeof(Arc));
+  arc = g_new0 (Arc, 1);
   orth = &arc->orth;
   obj = &orth->object;
 
diff --git a/objects/Istar/actor.c b/objects/Istar/actor.c
index 47d9f5724..85c83ef04 100644
--- a/objects/Istar/actor.c
+++ b/objects/Istar/actor.c
@@ -468,7 +468,7 @@ actor_create(Point *startpoint,
   int i;
   DiaFont *font = NULL;
 
-  actor = g_malloc0(sizeof(Actor));
+  actor = g_new0 (Actor, 1);
   elem = &actor->element;
   obj = &elem->object;
 
diff --git a/objects/Istar/goal.c b/objects/Istar/goal.c
index 1cce48b12..693498ebc 100644
--- a/objects/Istar/goal.c
+++ b/objects/Istar/goal.c
@@ -543,7 +543,7 @@ goal_create(Point *startpoint,
   DiaFont* font;
   int i;
 
-  goal = g_malloc0(sizeof(Goal));
+  goal = g_new0 (Goal, 1);
   elem = &goal->element;
   obj = &elem->object;
 
diff --git a/objects/Istar/link.c b/objects/Istar/link.c
index 36fbc0ea8..50e64ec9f 100644
--- a/objects/Istar/link.c
+++ b/objects/Istar/link.c
@@ -545,7 +545,7 @@ link_create(Point *startpoint,
     link_font = dia_font_new_from_style(DIA_FONT_SANS, LINK_FONTHEIGHT);
   }
 
-  link = g_malloc0(sizeof(Link));
+  link = g_new0 (Link, 1);
 
   conn = &link->connection;
   conn->endpoints[0] = *startpoint;
diff --git a/objects/Istar/other.c b/objects/Istar/other.c
index 0fac9f982..a31cfa2f4 100644
--- a/objects/Istar/other.c
+++ b/objects/Istar/other.c
@@ -568,7 +568,7 @@ other_create(Point *startpoint,
   Point p;
   DiaFont* font;
 
-  other = g_malloc0(sizeof(Other));
+  other = g_new0 (Other, 1);
   elem = &other->element;
   obj = &elem->object;
 
diff --git a/objects/Jackson/domain.c b/objects/Jackson/domain.c
index b2022032f..f6950ff40 100644
--- a/objects/Jackson/domain.c
+++ b/objects/Jackson/domain.c
@@ -658,7 +658,7 @@ jackson_box_create (Point   *startpoint,
   Point p;
   DiaFont* font;
 
-  box = g_malloc0 (sizeof (Box));
+  box = g_new0 (Box, 1);
   elem = &box->element;
   obj = &elem->object;
 
diff --git a/objects/Jackson/phenomenon.c b/objects/Jackson/phenomenon.c
index 0bf609d0a..646ec79a3 100644
--- a/objects/Jackson/phenomenon.c
+++ b/objects/Jackson/phenomenon.c
@@ -322,7 +322,7 @@ message_create(Point *startpoint,
       dia_font_new_from_style (DIA_FONT_SANS, MESSAGE_FONTHEIGHT);
   }
 
-  message = g_malloc0(sizeof(Message));
+  message = g_new0 (Message, 1);
 
   conn = &message->connection;
   conn->endpoints[0] = *startpoint;
diff --git a/objects/Jackson/requirement.c b/objects/Jackson/requirement.c
index 0d975b6d7..e7925ce0a 100644
--- a/objects/Jackson/requirement.c
+++ b/objects/Jackson/requirement.c
@@ -345,7 +345,7 @@ req_create(Point *startpoint,
   DiaFont *font;
   int i;
 
-  req = g_malloc0(sizeof(Requirement));
+  req = g_new0 (Requirement, 1);
   elem = &req->element;
   obj = &elem->object;
 
diff --git a/objects/KAOS/goal.c b/objects/KAOS/goal.c
index f86ebcef7..5bd10314d 100644
--- a/objects/KAOS/goal.c
+++ b/objects/KAOS/goal.c
@@ -698,7 +698,7 @@ goal_create(Point *startpoint,
   Point p;
   DiaFont* font;
 
-  goal = g_malloc0(sizeof(Goal));
+  goal = g_new0 (Goal, 1);
   elem = &goal->element;
   obj = &elem->object;
 
diff --git a/objects/KAOS/metaandorrel.c b/objects/KAOS/metaandorrel.c
index af518d44c..88fac883d 100644
--- a/objects/KAOS/metaandorrel.c
+++ b/objects/KAOS/metaandorrel.c
@@ -514,7 +514,7 @@ maor_create (Point   *startpoint,
       dia_font_new_from_style (DIA_FONT_SANS, MAOR_FONTHEIGHT);
   }
 
-  maor = g_malloc0 (sizeof (Maor));
+  maor = g_new0 (Maor, 1);
 
   conn = &maor->connection;
   conn->endpoints[0] = *startpoint;
diff --git a/objects/KAOS/metabinrel.c b/objects/KAOS/metabinrel.c
index d491555dd..c07c9401f 100644
--- a/objects/KAOS/metabinrel.c
+++ b/objects/KAOS/metabinrel.c
@@ -481,7 +481,7 @@ mbr_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle
     mbr_font = dia_font_new_from_style(DIA_FONT_SANS, MBR_DECFONTHEIGHT);
   }
 
-  mbr = g_malloc0(sizeof(Mbr));
+  mbr = g_new0 (Mbr, 1);
 
   conn = &mbr->connection;
   conn->endpoints[0] = *startpoint;
diff --git a/objects/KAOS/other.c b/objects/KAOS/other.c
index 5f0983dbe..5ba2df68d 100644
--- a/objects/KAOS/other.c
+++ b/objects/KAOS/other.c
@@ -637,7 +637,7 @@ other_create(Point *startpoint,
   Point p;
   DiaFont* font;
 
-  other = g_malloc0(sizeof(Other));
+  other = g_new0 (Other, 1);
   elem = &other->element;
   obj = &elem->object;
 
diff --git a/objects/Misc/grid_object.c b/objects/Misc/grid_object.c
index 2ee926058..027a9d217 100644
--- a/objects/Misc/grid_object.c
+++ b/objects/Misc/grid_object.c
@@ -477,13 +477,14 @@ grid_object_reallocate_cells (Grid_Object* grid_object)
   /* obj->connections doesn't own the pointers, so just realloc; values
    * will be updated later */
   obj->num_connections = GRID_OBJECT_BASE_CONNECTION_POINTS + new_rows*new_cols;
-  obj->connections = (ConnectionPoint **) g_realloc(obj->connections,
-               obj->num_connections * sizeof(ConnectionPoint *));
+  obj->connections = g_renew (ConnectionPoint *,
+                              obj->connections,
+                              obj->num_connections);
 
   /* Can't use realloc; if grid has different dims, memory lays out
    * differently.  Must copy by hand. */
 
-  new_cells = g_malloc(new_rows * new_cols * sizeof(ConnectionPoint));
+  new_cells = g_new0 (ConnectionPoint, new_rows * new_cols);
   for (i = 0; i < new_cols; ++i)
     for (j = 0; j < new_rows; ++j)
     {
diff --git a/objects/Misc/tree.c b/objects/Misc/tree.c
index d09d956f2..a02a4bef5 100644
--- a/objects/Misc/tree.c
+++ b/objects/Misc/tree.c
@@ -351,9 +351,8 @@ tree_create(Point *startpoint,
   LineBBExtras *extra;
   DiaObject *obj;
   Point defaultlen = { 0.0, 20.0 };
-  int i;
 
-  tree = g_malloc0(sizeof(Tree));
+  tree = g_new0 (Tree, 1);
 
   conn = &tree->connection;
   conn->endpoints[0] = *startpoint;
@@ -370,10 +369,10 @@ tree_create(Point *startpoint,
 
   connection_init(conn, 2+tree->num_handles, 0);
   tree->line_color = attributes_get_foreground();
-  tree->handles = g_malloc(sizeof(Handle *)*tree->num_handles);
-  tree->parallel_points = g_malloc(sizeof(Point)*tree->num_handles);
-  for (i=0;i<tree->num_handles;i++) {
-    tree->handles[i] = g_new0(Handle,1);
+  tree->handles = g_new0 (Handle *, tree->num_handles);
+  tree->parallel_points = g_new0 (Point, tree->num_handles);
+  for (int i = 0; i < tree->num_handles; i++) {
+    tree->handles[i] = g_new0 (Handle,1);
     tree->handles[i]->id = HANDLE_BUS;
     tree->handles[i]->type = HANDLE_MINOR_CONTROL;
     tree->handles[i]->connect_type = HANDLE_CONNECTABLE_NOBREAK;
@@ -414,11 +413,10 @@ tree_copy(Tree *tree)
   Tree *newtree;
   Connection *conn, *newconn;
   DiaObject *newobj;
-  int i;
 
   conn = &tree->connection;
 
-  newtree = g_malloc0(sizeof(Tree));
+  newtree = g_new0 (Tree, 1);
   newconn = &newtree->connection;
   newobj = &newconn->object;
 
@@ -427,11 +425,11 @@ tree_copy(Tree *tree)
   newtree->num_handles = tree->num_handles;
   newtree->line_color = tree->line_color;
 
-  newtree->handles = g_malloc(sizeof(Handle *)*newtree->num_handles);
-  newtree->parallel_points = g_malloc(sizeof(Point)*newtree->num_handles);
+  newtree->handles = g_new0 (Handle *, newtree->num_handles);
+  newtree->parallel_points = g_new0 (Point, newtree->num_handles);
 
-  for (i=0;i<newtree->num_handles;i++) {
-    newtree->handles[i] = g_new0(Handle,1);
+  for (int i = 0; i < newtree->num_handles; i++) {
+    newtree->handles[i] = g_new0 (Handle, 1);
     *newtree->handles[i] = *tree->handles[i];
     newtree->handles[i]->connected_to = NULL;
     newobj->handles[2+i] = newtree->handles[i];
@@ -516,10 +514,8 @@ tree_add_handle(Tree *tree, Point *p, Handle *handle)
   tree->num_handles++;
 
   /* Allocate more handles */
-  tree->handles = g_realloc(tree->handles,
-                          sizeof(Handle *)*tree->num_handles);
-  tree->parallel_points = g_realloc(tree->parallel_points,
-                                  sizeof(Point)*tree->num_handles);
+  tree->handles = g_renew (Handle *, tree->handles, tree->num_handles);
+  tree->parallel_points = g_renew (Point, tree->parallel_points, tree->num_handles);
 
   i = tree->num_handles - 1;
 
@@ -532,25 +528,24 @@ tree_add_handle(Tree *tree, Point *p, Handle *handle)
   object_add_handle(&tree->connection.object, tree->handles[i]);
 }
 
+
 static void
-tree_remove_handle(Tree *tree, Handle *handle)
+tree_remove_handle (Tree *tree, Handle *handle)
 {
-  int i, j;
-
-  for (i=0;i<tree->num_handles;i++) {
+  for (int i = 0; i < tree->num_handles; i++) {
     if (tree->handles[i] == handle) {
-      object_remove_handle(&tree->connection.object, handle);
+      object_remove_handle (&tree->connection.object, handle);
 
-      for (j=i;j<tree->num_handles-1;j++) {
-       tree->handles[j] = tree->handles[j+1];
-       tree->parallel_points[j] = tree->parallel_points[j+1];
+      for (int j = i; j < tree->num_handles - 1; j++) {
+        tree->handles[j] = tree->handles[j+1];
+        tree->parallel_points[j] = tree->parallel_points[j+1];
       }
 
       tree->num_handles--;
-      tree->handles = g_realloc(tree->handles,
-                              sizeof(Handle *)*tree->num_handles);
-      tree->parallel_points = g_realloc(tree->parallel_points,
-                                      sizeof(Point)*tree->num_handles);
+      tree->handles = g_renew (Handle *, tree->handles, tree->num_handles);
+      tree->parallel_points = g_renew (Point,
+                                       tree->parallel_points,
+                                       tree->num_handles);
 
       break;
     }
@@ -667,9 +662,8 @@ tree_load(ObjectNode obj_node, int version,DiaContext *ctx)
   DiaObject *obj;
   AttributeNode attr;
   DataNode data;
-  int i;
 
-  tree = g_malloc0(sizeof(Tree));
+  tree = g_new0 (Tree, 1);
 
   conn = &tree->connection;
   obj = &conn->object;
@@ -689,10 +683,10 @@ tree_load(ObjectNode obj_node, int version,DiaContext *ctx)
   connection_init(conn, 2 + tree->num_handles, 0);
 
   data = attribute_first_data(attr);
-  tree->handles = g_malloc(sizeof(Handle *)*tree->num_handles);
-  tree->parallel_points = g_malloc(sizeof(Point)*tree->num_handles);
-  for (i=0;i<tree->num_handles;i++) {
-    tree->handles[i] = g_new0(Handle,1);
+  tree->handles = g_new0 (Handle *, tree->num_handles);
+  tree->parallel_points = g_new0 (Point, tree->num_handles);
+  for (int i = 0; i < tree->num_handles; i++) {
+    tree->handles[i] = g_new0 (Handle, 1);
     tree->handles[i]->id = HANDLE_BUS;
     tree->handles[i]->type = HANDLE_MINOR_CONTROL;
     tree->handles[i]->connect_type = HANDLE_CONNECTABLE_NOBREAK;
diff --git a/objects/SADT/annotation.c b/objects/SADT/annotation.c
index b8d676917..d3654a3bc 100644
--- a/objects/SADT/annotation.c
+++ b/objects/SADT/annotation.c
@@ -333,7 +333,7 @@ annotation_create(Point *startpoint,
   Point defaultlen = { 1.0, 1.0 };
   DiaFont* font;
 
-  annotation = g_malloc0(sizeof(Annotation));
+  annotation = g_new0 (Annotation, 1);
 
   conn = &annotation->connection;
   conn->endpoints[0] = *startpoint;
diff --git a/objects/SADT/arrow.c b/objects/SADT/arrow.c
index eaa0d2243..c7782f790 100644
--- a/objects/SADT/arrow.c
+++ b/objects/SADT/arrow.c
@@ -396,7 +396,7 @@ sadtarrow_create(Point *startpoint,
   OrthConn *orth;
   DiaObject *obj;
 
-  sadtarrow = g_malloc0(sizeof(Sadtarrow));
+  sadtarrow = g_new0 (Sadtarrow, 1);
   orth = &sadtarrow->orth;
   obj = &orth->object;
 
diff --git a/objects/SADT/box.c b/objects/SADT/box.c
index 1a34cd3e1..95fc2cb05 100644
--- a/objects/SADT/box.c
+++ b/objects/SADT/box.c
@@ -532,7 +532,7 @@ sadtbox_create(Point *startpoint,
   Point p;
   DiaFont* font;
 
-  box = g_malloc0(sizeof(Box));
+  box = g_new0 (Box, 1);
   elem = &box->element;
   obj = &elem->object;
 
diff --git a/objects/UML/activity.c b/objects/UML/activity.c
index b131316df..c23338f4f 100644
--- a/objects/UML/activity.c
+++ b/objects/UML/activity.c
@@ -285,7 +285,7 @@ state_create_activity(Point *startpoint,
   DiaFont *font;
   int i;
 
-  state = g_malloc0(sizeof(State));
+  state = g_new0 (State, 1);
   elem = &state->element;
   obj = &elem->object;
 
diff --git a/objects/UML/actor.c b/objects/UML/actor.c
index 630a2fe17..2b9a6b776 100644
--- a/objects/UML/actor.c
+++ b/objects/UML/actor.c
@@ -339,7 +339,7 @@ actor_create(Point *startpoint,
   DiaFont *font;
   int i;
 
-  actor = g_malloc0(sizeof(Actor));
+  actor = g_new0 (Actor, 1);
   elem = &actor->element;
   obj = &elem->object;
 
diff --git a/objects/UML/association.c b/objects/UML/association.c
index 9cd5bdd02..6c03cbac6 100644
--- a/objects/UML/association.c
+++ b/objects/UML/association.c
@@ -822,7 +822,7 @@ association_create (Point   *startpoint,
   int i;
   int user_d;
 
-  assoc = g_malloc0 (sizeof (Association));
+  assoc = g_new0 (Association, 1);
   orth = &assoc->orth;
   obj = &orth->object;
 
@@ -960,7 +960,7 @@ association_copy (Association *assoc)
 
   orth = &assoc->orth;
 
-  newassoc = g_malloc0 (sizeof (Association));
+  newassoc = g_new0 (Association, 1);
   neworth = &newassoc->orth;
 
   orthconn_copy (orth, neworth);
diff --git a/objects/UML/branch.c b/objects/UML/branch.c
index 4cf140781..bd1b51957 100644
--- a/objects/UML/branch.c
+++ b/objects/UML/branch.c
@@ -257,7 +257,7 @@ branch_create(Point *startpoint, void *user_data, Handle **handle1, Handle **han
   DiaObject *obj;
   int i;
 
-  branch = g_malloc0(sizeof(Branch));
+  branch = g_new0 (Branch, 1);
   elem = &branch->element;
   obj = &elem->object;
 
diff --git a/objects/UML/class.c b/objects/UML/class.c
index b71d737cc..ce5de0233 100644
--- a/objects/UML/class.c
+++ b/objects/UML/class.c
@@ -470,7 +470,9 @@ umlclass_set_props(UMLClass *umlclass, GPtrArray *props)
   obj->num_connections = num;
 #endif
 
-  obj->connections =  g_realloc(obj->connections, obj->num_connections*sizeof(ConnectionPoint *));
+  obj->connections = g_renew (ConnectionPoint *,
+                              obj->connections,
+                              obj->num_connections);
 
   /* Update data: */
   if (num > UMLCLASS_CONNECTIONPOINTS) {
@@ -683,7 +685,7 @@ uml_create_documentation_tag (gchar * comment,
   gint     WorkingWrapPoint = (TagLength<WrapPoint) ? WrapPoint : ((TagLength<=0)?1:TagLength);
   gint     RawLength        = TagLength + strlen(comment) + (tagging?1:0);
   gint     MaxCookedLength  = RawLength + RawLength/WorkingWrapPoint;
-  gchar    *WrappedComment  = g_malloc0(MaxCookedLength+1);
+  gchar    *WrappedComment  = g_new0 (char, MaxCookedLength + 1);
   gint     AvailSpace       = WorkingWrapPoint - TagLength;
   gchar    *Scan;
   gchar    *BreakCandidate;
@@ -1080,10 +1082,12 @@ umlclass_draw_operationbox (UMLClass    *umlclass,
             part_opstr_need = wrap_pos + 1;
             if (part_opstr_len < part_opstr_need) {
               part_opstr_len = part_opstr_need;
-              part_opstr = g_realloc (part_opstr, part_opstr_need);
+              part_opstr = g_renew (char, part_opstr, part_opstr_need);
             } else {
               /* ensure to never strncpy to NULL and not shrink */
-              part_opstr = g_realloc (part_opstr, MAX (part_opstr_need, part_opstr_len));
+              part_opstr = g_renew (char,
+                                    part_opstr,
+                                    MAX (part_opstr_need, part_opstr_len));
             }
             strncpy (part_opstr, opstr, wrap_pos);
             memset (part_opstr+wrap_pos, '\0', 1);
@@ -1091,7 +1095,7 @@ umlclass_draw_operationbox (UMLClass    *umlclass,
             part_opstr_need = ident + wrap_pos - last_wrap_pos + 1;
             if (part_opstr_len < part_opstr_need) {
               part_opstr_len = part_opstr_need;
-              part_opstr = g_realloc (part_opstr, part_opstr_need);
+              part_opstr = g_renew (char, part_opstr, part_opstr_need);
             }
             memset (part_opstr, ' ', ident);
             memset (part_opstr+ident, '\0', 1);
@@ -1874,7 +1878,7 @@ umlclass_create(Point *startpoint,
   DiaObject *obj;
   int i;
 
-  umlclass = g_malloc0(sizeof(UMLClass));
+  umlclass = g_new0 (UMLClass, 1);
   elem = &umlclass->element;
   obj = &elem->object;
 
@@ -2030,7 +2034,7 @@ umlclass_copy(UMLClass *umlclass)
 
   elem = &umlclass->element;
 
-  newumlclass = g_malloc0(sizeof(UMLClass));
+  newumlclass = g_new0 (UMLClass, 1);
   newelem = &newumlclass->element;
   newobj = &newelem->object;
 
@@ -2307,7 +2311,7 @@ umlclass_load (ObjectNode obj_node, int version, DiaContext *ctx)
   GList *list;
 
 
-  umlclass = g_malloc0 (sizeof (UMLClass));
+  umlclass = g_new0 (UMLClass, 1);
   elem = &umlclass->element;
   obj = &elem->object;
 
diff --git a/objects/UML/class_dialog.c b/objects/UML/class_dialog.c
index 22ec2e3e6..d66218720 100644
--- a/objects/UML/class_dialog.c
+++ b/objects/UML/class_dialog.c
@@ -629,9 +629,9 @@ umlclass_apply_props_from_dialog (UMLClass *umlclass, GtkWidget *widget)
   obj->num_connections =
     UMLCLASS_CONNECTIONPOINTS + num_attrib*2 + num_ops*2;
 #endif
-  obj->connections =
-    g_realloc(obj->connections,
-             obj->num_connections*sizeof(ConnectionPoint *));
+  obj->connections = g_renew (ConnectionPoint *,
+                              obj->connections,
+                              obj->num_connections);
 
   /* Read from dialog and put in object: */
   class_read_from_dialog(umlclass, prop_dialog);
@@ -871,9 +871,9 @@ umlclass_update_connectionpoints(UMLClass *umlclass)
 #else
   obj->num_connections = UMLCLASS_CONNECTIONPOINTS + num_attrib*2 + num_ops*2;
 #endif
-  obj->connections =
-    g_realloc(obj->connections,
-             obj->num_connections*sizeof(ConnectionPoint *));
+  obj->connections = g_renew (ConnectionPoint *,
+                              obj->connections,
+                              obj->num_connections);
 
   connection_index = UMLCLASS_CONNECTIONPOINTS;
 
diff --git a/objects/UML/classicon.c b/objects/UML/classicon.c
index b2a8b4b4e..959e3752b 100644
--- a/objects/UML/classicon.c
+++ b/objects/UML/classicon.c
@@ -427,7 +427,7 @@ classicon_create(Point *startpoint,
   DiaFont *font;
   int i;
 
-  cicon = g_malloc0(sizeof(Classicon));
+  cicon = g_new0 (Classicon, 1);
 
   /* old default */
   cicon->line_width = 0.1;
diff --git a/objects/UML/component.c b/objects/UML/component.c
index dde444d0c..383b5a4b8 100644
--- a/objects/UML/component.c
+++ b/objects/UML/component.c
@@ -391,7 +391,7 @@ component_create(Point *startpoint,
   DiaFont *font;
   int i;
 
-  cmp = g_malloc0(sizeof(Component));
+  cmp = g_new0 (Component, 1);
   elem = &cmp->element;
   obj = &elem->object;
 
diff --git a/objects/UML/constraint.c b/objects/UML/constraint.c
index b39b2cd82..f67b190ce 100644
--- a/objects/UML/constraint.c
+++ b/objects/UML/constraint.c
@@ -292,7 +292,7 @@ constraint_create(Point *startpoint,
   DiaObject *obj;
   Point defaultlen = { 1.0, 1.0 };
 
-  constraint = g_malloc0(sizeof(Constraint));
+  constraint = g_new0 (Constraint, 1);
 
   /* old defaults */
   constraint->font_height = 0.8;
diff --git a/objects/UML/fork.c b/objects/UML/fork.c
index 901edf3a6..4e6cd6026 100644
--- a/objects/UML/fork.c
+++ b/objects/UML/fork.c
@@ -265,7 +265,7 @@ fork_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handl
   DiaObject *obj;
   int i;
 
-  branch = g_malloc0(sizeof(Fork));
+  branch = g_new0 (Fork, 1);
   elem = &branch->element;
   obj = &elem->object;
 
diff --git a/objects/UML/implements.c b/objects/UML/implements.c
index 980d69ca8..a773db7d8 100644
--- a/objects/UML/implements.c
+++ b/objects/UML/implements.c
@@ -303,7 +303,7 @@ implements_create(Point *startpoint,
   DiaObject *obj;
   Point defaultlen = { 1.0, 1.0 };
 
-  implements = g_malloc0(sizeof(Implements));
+  implements = g_new0 (Implements, 1);
 
   /* old defaults */
   implements->font_height = 0.8;
diff --git a/objects/UML/large_package.c b/objects/UML/large_package.c
index 77430af9f..9e4d7fbcd 100644
--- a/objects/UML/large_package.c
+++ b/objects/UML/large_package.c
@@ -357,7 +357,7 @@ largepackage_create(Point *startpoint,
   DiaObject *obj;
   int i;
 
-  pkg = g_malloc0(sizeof(LargePackage));
+  pkg = g_new0 (LargePackage, 1);
   elem = &pkg->element;
   obj = &elem->object;
 
diff --git a/objects/UML/lifeline.c b/objects/UML/lifeline.c
index 174933c33..50b7d6a92 100644
--- a/objects/UML/lifeline.c
+++ b/objects/UML/lifeline.c
@@ -603,7 +603,7 @@ lifeline_create(Point *startpoint,
   DiaObject *obj;
   int i;
 
-  lifeline = g_malloc0(sizeof(Lifeline));
+  lifeline = g_new0 (Lifeline, 1);
   lifeline->cp_distance = LIFELINE_CP_DEFAULT_DISTANCE;
 
   conn = &lifeline->connection;
diff --git a/objects/UML/message.c b/objects/UML/message.c
index ff306cfd8..b37d52a0e 100644
--- a/objects/UML/message.c
+++ b/objects/UML/message.c
@@ -375,7 +375,7 @@ message_create(Point *startpoint,
   LineBBExtras *extra;
   DiaObject *obj;
 
-  message = g_malloc0(sizeof(Message));
+  message = g_new0 (Message, 1);
 
   /* old defaults */
   message->font_height = 0.8;
diff --git a/objects/UML/node.c b/objects/UML/node.c
index 8e9643c7b..8cbfca6dd 100644
--- a/objects/UML/node.c
+++ b/objects/UML/node.c
@@ -324,7 +324,7 @@ static DiaObject *node_create(Point *startpoint, void *user_data, Handle **handl
   DiaFont *font;
   int i;
 
-  node = g_malloc0(sizeof(Node));
+  node = g_new0 (Node, 1);
 
   /* old defaults */
   node->line_width = NODE_BORDERWIDTH;
diff --git a/objects/UML/note.c b/objects/UML/note.c
index 69a121747..570ae5b7c 100644
--- a/objects/UML/note.c
+++ b/objects/UML/note.c
@@ -300,7 +300,7 @@ note_create(Point *startpoint,
   DiaFont *font;
   int i;
 
-  note = g_malloc0(sizeof(Note));
+  note = g_new0 (Note, 1);
   elem = &note->element;
   obj = &elem->object;
 
diff --git a/objects/UML/object.c b/objects/UML/object.c
index 82037388e..57aa176cd 100644
--- a/objects/UML/object.c
+++ b/objects/UML/object.c
@@ -462,7 +462,7 @@ objet_create(Point *startpoint,
   DiaFont *font;
   int i;
 
-  ob = g_malloc0(sizeof(Objet));
+  ob = g_new0 (Objet, 1);
   elem = &ob->element;
   obj = &elem->object;
 
diff --git a/objects/UML/realizes.c b/objects/UML/realizes.c
index 585075d9e..05ec8a84f 100644
--- a/objects/UML/realizes.c
+++ b/objects/UML/realizes.c
@@ -424,7 +424,7 @@ realizes_create(Point *startpoint,
   DiaObject *obj;
   PolyBBExtras *extra;
 
-  realize = g_malloc0(sizeof(Realizes));
+  realize = g_new0 (Realizes, 1);
   /* old defaults */
   realize->font_height = 0.8;
   realize->font =
diff --git a/objects/UML/small_package.c b/objects/UML/small_package.c
index 5d8df3856..af27dcf1c 100644
--- a/objects/UML/small_package.c
+++ b/objects/UML/small_package.c
@@ -346,7 +346,7 @@ smallpackage_create(Point *startpoint,
   DiaFont *font;
   int i;
 
-  pkg = g_malloc0(sizeof(SmallPackage));
+  pkg = g_new0 (SmallPackage, 1);
   elem = &pkg->element;
   obj = &elem->object;
 
diff --git a/objects/UML/state.c b/objects/UML/state.c
index cc7b45d4a..14bacd698 100644
--- a/objects/UML/state.c
+++ b/objects/UML/state.c
@@ -425,7 +425,7 @@ state_create(Point *startpoint,
   DiaFont *font;
   int i;
 
-  state = g_malloc0(sizeof(State));
+  state = g_new0 (State, 1);
 
   /* old default */
   state->line_width = 0.1;
diff --git a/objects/UML/state_term.c b/objects/UML/state_term.c
index 12b20b399..da339f4fe 100644
--- a/objects/UML/state_term.c
+++ b/objects/UML/state_term.c
@@ -270,7 +270,7 @@ state_create(Point *startpoint,
   Point p;
   int i;
 
-  state = g_malloc0(sizeof(State));
+  state = g_new0 (State, 1);
   elem = &state->element;
   obj = &elem->object;
 
diff --git a/objects/UML/umlattribute.c b/objects/UML/umlattribute.c
index 753d638b6..212b6d1f7 100644
--- a/objects/UML/umlattribute.c
+++ b/objects/UML/umlattribute.c
@@ -219,7 +219,7 @@ uml_attribute_get_string (UMLAttribute *attribute)
     len += 3 + strlen (attribute->value);
   }
 
-  str = g_malloc (sizeof (char) * (len + 1));
+  str = g_new0 (char, len + 1);
 
   str[0] = visible_char[(int) attribute->visibility];
   str[1] = 0;
diff --git a/objects/UML/umlformalparameter.c b/objects/UML/umlformalparameter.c
index 4b6fc8239..9bdc14925 100644
--- a/objects/UML/umlformalparameter.c
+++ b/objects/UML/umlformalparameter.c
@@ -133,7 +133,7 @@ uml_formal_parameter_get_string (UMLFormalParameter *parameter)
   }
 
   /* Generate string: */
-  str = g_malloc (sizeof (char) * (len + 1));
+  str = g_new0 (char, len + 1);
   strcpy (str, parameter->name ? parameter->name : "");
   if (parameter->type != NULL) {
     strcat (str, ":");
diff --git a/objects/UML/umloperation.c b/objects/UML/umloperation.c
index deac13d55..daa5dc448 100644
--- a/objects/UML/umloperation.c
+++ b/objects/UML/umloperation.c
@@ -338,7 +338,7 @@ uml_get_operation_string (UMLOperation *operation)
   }
 
   /* generate string: */
-  str = g_malloc (sizeof (char) * (len + 1));
+  str = g_new0 (char, len + 1);
 
   str[0] = visible_char[(int) operation->visibility];
   str[1] = 0;
diff --git a/objects/UML/umlparameter.c b/objects/UML/umlparameter.c
index f9e7a2f25..7525001b9 100644
--- a/objects/UML/umlparameter.c
+++ b/objects/UML/umlparameter.c
@@ -170,7 +170,7 @@ uml_parameter_get_string (UMLParameter *param)
   }
 
   /* Generate string: */
-  str = g_malloc (sizeof (char) * (len + 1));
+  str = g_new0 (char, len + 1);
 
   strcpy (str, "");
 
diff --git a/objects/UML/usecase.c b/objects/UML/usecase.c
index 1146ccbd4..19db659c7 100644
--- a/objects/UML/usecase.c
+++ b/objects/UML/usecase.c
@@ -400,7 +400,7 @@ usecase_create(Point *startpoint,
   DiaFont *font;
   int i;
 
-  usecase = g_malloc0(sizeof(Usecase));
+  usecase = g_new0 (Usecase, 1);
   elem = &usecase->element;
   obj = &elem->object;
 
diff --git a/objects/custom/custom_object.c b/objects/custom/custom_object.c
index 327bac550..a1d51dc8f 100644
--- a/objects/custom/custom_object.c
+++ b/objects/custom/custom_object.c
@@ -1671,7 +1671,7 @@ custom_create(Point *startpoint,
   if (!info->loaded) /* called for it's side effect */
     shape_info_getbyname (info->name);
 
-  custom = g_new0_ext (Custom, info->ext_attr_size);
+  custom = dia_new_with_extra (sizeof (Custom), 1, info->ext_attr_size);
   elem = &custom->element;
   obj = &elem->object;
 
@@ -1781,7 +1781,7 @@ custom_copy(Custom *custom)
   elem = &custom->element;
   /* can't use object_copy_using_properties() becauses there is no way
    * to pass in our creation data (info) ... */
-  newcustom = g_new0_ext (Custom, custom->info->ext_attr_size);
+  newcustom = dia_new_with_extra (sizeof (Custom), 1, custom->info->ext_attr_size);
   newelem = &newcustom->element;
   newobj = &newcustom->element.object;
 
diff --git a/objects/custom/shape_info.c b/objects/custom/shape_info.c
index 5549e39ec..71ff404b8 100644
--- a/objects/custom/shape_info.c
+++ b/objects/custom/shape_info.c
@@ -175,22 +175,24 @@ parse_path(ShapeInfo *info, const char *path_str, DiaSvgStyle *s, const char* fi
                           dia_message_filename(filename));
       } else if (closed) {
         /* if there is some unclosed commands, add them as a GE_SHAPE */
-       GraphicElementPath *el = g_malloc(sizeof(GraphicElementPath) +
-                                           points->len * sizeof(BezPoint));
-       el->type = GE_SHAPE;
-       dia_svg_style_init (&el->s, s);
-       el->npoints = points->len;
-       memcpy((char *)el->points, points->data, points->len*sizeof(BezPoint));
-       info->display_list = g_list_append(info->display_list, el);
+        GraphicElementPath *el = dia_new_with_extra (sizeof (GraphicElementPath),
+                                                     points->len,
+                                                     sizeof (BezPoint));
+        el->type = GE_SHAPE;
+        dia_svg_style_init (&el->s, s);
+        el->npoints = points->len;
+        memcpy ((char *) el->points, points->data, points->len * sizeof(BezPoint));
+        info->display_list = g_list_append (info->display_list, el);
       } else {
         /* if there is some unclosed commands, add them as a GE_PATH */
-       GraphicElementPath *el = g_malloc(sizeof(GraphicElementPath) +
-                                         points->len * sizeof(BezPoint));
-       el->type = GE_PATH;
-       dia_svg_style_init (&el->s, s);
-       el->npoints = points->len;
-       memcpy((char *)el->points, points->data, points->len*sizeof(BezPoint));
-       info->display_list = g_list_append(info->display_list, el);
+        GraphicElementPath *el = dia_new_with_extra (sizeof (GraphicElementPath),
+                                                     points->len,
+                                                     sizeof (BezPoint));
+        el->type = GE_PATH;
+        dia_svg_style_init (&el->s, s);
+        el->npoints = points->len;
+        memcpy ((char *) el->points, points->data, points->len * sizeof (BezPoint));
+        info->display_list = g_list_append(info->display_list, el);
       }
       g_array_set_size (points, 0);
     }
@@ -288,7 +290,9 @@ parse_svg_node(ShapeInfo *info, xmlNodePtr node, xmlNsPtr svg_ns,
       val = 0;
       if (arr->len % 2 == 1)
         g_array_append_val(arr, val);
-      poly = g_malloc0(sizeof(GraphicElementPoly) + arr->len/2*sizeof(Point));
+      poly = dia_new_with_extra (sizeof (GraphicElementPoly),
+                                 arr->len / 2,
+                                 sizeof (Point));
       el = (GraphicElement *)poly;
       poly->type = GE_POLYLINE;
       poly->npoints = arr->len / 2;
@@ -319,7 +323,9 @@ parse_svg_node(ShapeInfo *info, xmlNodePtr node, xmlNsPtr svg_ns,
       val = 0;
       if (arr->len % 2 == 1)
         g_array_append_val(arr, val);
-      poly = g_malloc0(sizeof(GraphicElementPoly) + arr->len/2*sizeof(Point));
+      poly = dia_new_with_extra (sizeof (GraphicElementPoly),
+                                 arr->len / 2,
+                                 sizeof (Point));
       el = (GraphicElement *)poly;
       poly->type = GE_POLYGON;
       poly->npoints = arr->len / 2;
diff --git a/objects/custom/shape_info.h b/objects/custom/shape_info.h
index 5d18719b5..d0af8d440 100644
--- a/objects/custom/shape_info.h
+++ b/objects/custom/shape_info.h
@@ -21,8 +21,8 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
-#ifndef _SHAPE_INFO_H_
-#define _SHAPE_INFO_H_
+
+#pragma once
 
 #include <glib.h>
 
@@ -34,6 +34,8 @@
 #include "intl.h"
 #include "dia_svg.h"
 
+G_BEGIN_DECLS
+
 typedef enum {
   GE_LINE,
   GE_POLYLINE,
@@ -227,9 +229,20 @@ void shape_info_print(ShapeInfo *info);
 void shape_info_register (ShapeInfo *);
 gboolean shape_typeinfo_load (ShapeInfo* info);
 
-/*MC 11/03 handy g_new0 variant for struct with variable size */
-#define g_new0_ext(struct_type, ext_size)              \
-    ((struct_type *) g_malloc0 ((gsize) (sizeof (struct_type) + ext_size)))
+static inline gpointer G_GNUC_MALLOC
+dia_new_with_extra (size_t n_main_bytes, size_t n_extra, size_t n_extra_bytes)
+{
+  if (G_LIKELY (n_extra_bytes == 0 || n_extra <= G_MAXSIZE / n_extra_bytes)) {
+    size_t points_size = n_extra * n_extra_bytes;
+    if (G_LIKELY (G_MAXSIZE - points_size >= n_main_bytes)) {
+      return g_malloc0 (points_size + n_main_bytes);
+    }
+  }
+
+  g_error ("%s: overflow allocating %"G_GSIZE_FORMAT"+(%"G_GSIZE_FORMAT"*%"G_GSIZE_FORMAT") bytes",
+           G_STRLOC, n_main_bytes, n_extra, n_extra_bytes);
 
-#endif
+  return NULL;
+}
 
+G_END_DECLS
diff --git a/objects/flowchart/box.c b/objects/flowchart/box.c
index 8c6e4514f..e24ab2d2e 100644
--- a/objects/flowchart/box.c
+++ b/objects/flowchart/box.c
@@ -576,7 +576,7 @@ box_create(Point *startpoint,
 
   init_default_values();
 
-  box = g_malloc0(sizeof(Box));
+  box = g_new0 (Box, 1);
   elem = &box->element;
   obj = &elem->object;
 
@@ -683,7 +683,7 @@ box_load(ObjectNode obj_node, int version,DiaContext *ctx)
   int i;
   AttributeNode attr;
 
-  box = g_malloc0(sizeof(Box));
+  box = g_new0 (Box, 1);
   elem = &box->element;
   obj = &elem->object;
 
diff --git a/objects/flowchart/diamond.c b/objects/flowchart/diamond.c
index 23b5ddf05..e714e6b3b 100644
--- a/objects/flowchart/diamond.c
+++ b/objects/flowchart/diamond.c
@@ -546,7 +546,7 @@ diamond_create(Point *startpoint,
 
   init_default_values();
 
-  diamond = g_malloc0(sizeof(Diamond));
+  diamond = g_new0 (Diamond, 1);
   elem = &diamond->element;
   obj = &elem->object;
 
@@ -650,7 +650,7 @@ diamond_load(ObjectNode obj_node, int version,DiaContext *ctx)
   int i;
   AttributeNode attr;
 
-  diamond = g_malloc0(sizeof(Diamond));
+  diamond = g_new0 (Diamond, 1);
   elem = &diamond->element;
   obj = &elem->object;
 
diff --git a/objects/flowchart/ellipse.c b/objects/flowchart/ellipse.c
index 6c6134a2a..4a5c52bb6 100644
--- a/objects/flowchart/ellipse.c
+++ b/objects/flowchart/ellipse.c
@@ -525,7 +525,7 @@ ellipse_create(Point *startpoint,
 
   init_default_values();
 
-  ellipse = g_malloc0(sizeof(Ellipse));
+  ellipse = g_new0 (Ellipse, 1);
   elem = &ellipse->element;
   obj = &elem->object;
 
@@ -628,7 +628,7 @@ ellipse_load(ObjectNode obj_node, int version,DiaContext *ctx)
   int i;
   AttributeNode attr;
 
-  ellipse = g_malloc0(sizeof(Ellipse));
+  ellipse = g_new0 (Ellipse, 1);
   elem = &ellipse->element;
   obj = &elem->object;
 
diff --git a/objects/flowchart/parallelogram.c b/objects/flowchart/parallelogram.c
index 213ccf7c9..fef2dc5ef 100644
--- a/objects/flowchart/parallelogram.c
+++ b/objects/flowchart/parallelogram.c
@@ -598,7 +598,7 @@ pgram_create(Point *startpoint,
 
   init_default_values();
 
-  pgram = g_malloc0(sizeof(Pgram));
+  pgram = g_new0 (Pgram, 1);
   elem = &pgram->element;
   obj = &elem->object;
 
@@ -705,7 +705,7 @@ pgram_load(ObjectNode obj_node, int version,DiaContext *ctx)
   int i;
   AttributeNode attr;
 
-  pgram = g_malloc0(sizeof(Pgram));
+  pgram = g_new0 (Pgram, 1);
   elem = &pgram->element;
   obj = &elem->object;
 
diff --git a/objects/network/bus.c b/objects/network/bus.c
index 6ba087bca..162645f34 100644
--- a/objects/network/bus.c
+++ b/objects/network/bus.c
@@ -352,9 +352,8 @@ bus_create(Point *startpoint,
   LineBBExtras *extra;
   DiaObject *obj;
   Point defaultlen = { 5.0, 0.0 };
-  int i;
 
-  bus = g_malloc0(sizeof(Bus));
+  bus = g_new0 (Bus, 1);
 
   conn = &bus->connection;
   conn->endpoints[0] = *startpoint;
@@ -371,10 +370,10 @@ bus_create(Point *startpoint,
 
   connection_init(conn, 2+bus->num_handles, 0);
   bus->line_color = attributes_get_foreground();
-  bus->handles = g_malloc(sizeof(Handle *)*bus->num_handles);
-  bus->parallel_points = g_malloc(sizeof(Point)*bus->num_handles);
-  for (i=0;i<bus->num_handles;i++) {
-    bus->handles[i] = g_new0(Handle,1);
+  bus->handles = g_new0 (Handle *, bus->num_handles);
+  bus->parallel_points = g_new0 (Point, bus->num_handles);
+  for (int i = 0; i < bus->num_handles; i++) {
+    bus->handles[i] = g_new0 (Handle, 1);
     bus->handles[i]->id = HANDLE_BUS;
     bus->handles[i]->type = HANDLE_MINOR_CONTROL;
     bus->handles[i]->connect_type = HANDLE_CONNECTABLE_NOBREAK;
@@ -414,11 +413,10 @@ bus_copy(Bus *bus)
   Bus *newbus;
   Connection *conn, *newconn;
   DiaObject *newobj;
-  int i;
 
   conn = &bus->connection;
 
-  newbus = g_malloc0(sizeof(Bus));
+  newbus = g_new0 (Bus, 1);
   newconn = &newbus->connection;
   newobj = &newconn->object;
 
@@ -427,11 +425,11 @@ bus_copy(Bus *bus)
   newbus->num_handles = bus->num_handles;
   newbus->line_color = bus->line_color;
 
-  newbus->handles = g_malloc(sizeof(Handle *)*newbus->num_handles);
-  newbus->parallel_points = g_malloc(sizeof(Point)*newbus->num_handles);
+  newbus->handles = g_new0 (Handle *, newbus->num_handles);
+  newbus->parallel_points = g_new0 (Point, newbus->num_handles);
 
-  for (i=0;i<newbus->num_handles;i++) {
-    newbus->handles[i] = g_new0(Handle,1);
+  for (int i = 0; i < newbus->num_handles; i++) {
+    newbus->handles[i] = g_new0 (Handle, 1);
     *newbus->handles[i] = *bus->handles[i];
     newbus->handles[i]->connected_to = NULL;
     newobj->handles[2+i] = newbus->handles[i];
@@ -508,18 +506,17 @@ bus_update_data(Bus *bus)
   connection_update_handles(conn);
 }
 
+
 static void
-bus_add_handle(Bus *bus, Point *p, Handle *handle)
+bus_add_handle (Bus *bus, Point *p, Handle *handle)
 {
   int i;
 
   bus->num_handles++;
 
   /* Allocate more handles */
-  bus->handles = g_realloc(bus->handles,
-                          sizeof(Handle *)*bus->num_handles);
-  bus->parallel_points = g_realloc(bus->parallel_points,
-                                  sizeof(Point)*bus->num_handles);
+  bus->handles = g_renew (Handle *, bus->handles, bus->num_handles);
+  bus->parallel_points = g_renew (Point, bus->parallel_points, bus->num_handles);
 
   i = bus->num_handles - 1;
 
@@ -547,10 +544,10 @@ bus_remove_handle(Bus *bus, Handle *handle)
       }
 
       bus->num_handles--;
-      bus->handles = g_realloc(bus->handles,
-                              sizeof(Handle *)*bus->num_handles);
-      bus->parallel_points = g_realloc(bus->parallel_points,
-                                      sizeof(Point)*bus->num_handles);
+      bus->handles = g_renew (Handle *, bus->handles, bus->num_handles);
+      bus->parallel_points = g_renew (Point,
+                                      bus->parallel_points,
+                                      bus->num_handles);
 
       break;
     }
@@ -666,9 +663,8 @@ bus_load(ObjectNode obj_node, int version,DiaContext *ctx)
   DiaObject *obj;
   AttributeNode attr;
   DataNode data;
-  int i;
 
-  bus = g_malloc0(sizeof(Bus));
+  bus = g_new0 (Bus, 1);
 
   conn = &bus->connection;
   obj = &conn->object;
@@ -688,10 +684,10 @@ bus_load(ObjectNode obj_node, int version,DiaContext *ctx)
   connection_init(conn, 2 + bus->num_handles, 0);
 
   data = attribute_first_data(attr);
-  bus->handles = g_malloc(sizeof(Handle *)*bus->num_handles);
-  bus->parallel_points = g_malloc(sizeof(Point)*bus->num_handles);
-  for (i=0;i<bus->num_handles;i++) {
-    bus->handles[i] = g_new0(Handle,1);
+  bus->handles = g_new0 (Handle *, bus->num_handles);
+  bus->parallel_points = g_new0 (Point, bus->num_handles);
+  for (int i = 0; i < bus->num_handles; i++) {
+    bus->handles[i] = g_new0 (Handle, 1);
     bus->handles[i]->id = HANDLE_BUS;
     bus->handles[i]->type = HANDLE_MINOR_CONTROL;
     bus->handles[i]->connect_type = HANDLE_CONNECTABLE_NOBREAK;
diff --git a/objects/network/wanlink.c b/objects/network/wanlink.c
index db788708a..10628740a 100644
--- a/objects/network/wanlink.c
+++ b/objects/network/wanlink.c
@@ -174,7 +174,7 @@ wanlink_create(Point *startpoint,
   Point defaultpoly = {0.0, 0.0};
   Point defaultlen = { 5.0, 0.0 };
 
-  wanlink = g_malloc0(sizeof(WanLink));
+  wanlink = g_new0 (WanLink, 1);
 
   conn = &wanlink->connection;
   conn->endpoints[0] = *startpoint;
@@ -253,7 +253,7 @@ wanlink_copy(WanLink *wanlink)
 
   conn = &wanlink->connection;
 
-  newwanlink = g_malloc0(sizeof(WanLink));
+  newwanlink = g_new0 (WanLink, 1);
   newconn = &newwanlink->connection;
 
   connection_copy(conn, newconn);
@@ -323,7 +323,7 @@ wanlink_load(ObjectNode obj_node, int version,DiaContext *ctx)
     AttributeNode attr;
     DataNode data;
 
-    wanlink = g_malloc0(sizeof(WanLink));
+    wanlink = g_new0 (WanLink, 1);
 
     conn = &wanlink->connection;
     obj = (DiaObject *) wanlink;
diff --git a/objects/standard/arc.c b/objects/standard/arc.c
index 425fc8358..cf70e6afc 100644
--- a/objects/standard/arc.c
+++ b/objects/standard/arc.c
@@ -699,7 +699,7 @@ arc_create(Point *startpoint,
   DiaObject *obj;
   Point defaultlen = { 1.0, 1.0 };
 
-  arc = g_malloc0(sizeof(Arc));
+  arc = g_new0 (Arc, 1);
   arc->connection.object.enclosing_box = g_new0 (DiaRectangle, 1);
 
   arc->line_width =  attributes_get_default_linewidth();
@@ -747,7 +747,7 @@ arc_copy(Arc *arc)
 
   conn = &arc->connection;
 
-  newarc = g_malloc0(sizeof(Arc));
+  newarc = g_new0 (Arc, 1);
   newarc->connection.object.enclosing_box = g_new0 (DiaRectangle, 1);
   newconn = &newarc->connection;
   newobj = &newconn->object;
@@ -989,7 +989,7 @@ arc_load(ObjectNode obj_node, int version,DiaContext *ctx)
   DiaObject *obj;
   AttributeNode attr;
 
-  arc = g_malloc0(sizeof(Arc));
+  arc = g_new0 (Arc, 1);
   arc->connection.object.enclosing_box = g_new0 (DiaRectangle, 1);
 
   conn = &arc->connection;
diff --git a/objects/standard/beziergon.c b/objects/standard/beziergon.c
index 9715f3705..3a3d3fdae 100644
--- a/objects/standard/beziergon.c
+++ b/objects/standard/beziergon.c
@@ -335,7 +335,7 @@ beziergon_copy(Beziergon *beziergon)
 
   bezier = &beziergon->bezier;
 
-  newbeziergon = g_malloc0(sizeof(Beziergon));
+  newbeziergon = g_new0 (Beziergon, 1);
   newbeziergon->bezier.object.enclosing_box = g_new0 (DiaRectangle, 1);
   newbezier = &newbeziergon->bezier;
 
@@ -428,7 +428,7 @@ beziergon_load(ObjectNode obj_node, int version, DiaContext *ctx)
   DiaObject *obj;
   AttributeNode attr;
 
-  beziergon = g_malloc0(sizeof(Beziergon));
+  beziergon = g_new0 (Beziergon, 1);
   beziergon->bezier.object.enclosing_box = g_new0 (DiaRectangle, 1);
 
   bez = &beziergon->bezier;
diff --git a/objects/standard/box.c b/objects/standard/box.c
index ffdb36953..903f745ac 100644
--- a/objects/standard/box.c
+++ b/objects/standard/box.c
@@ -493,7 +493,7 @@ box_create(Point *startpoint,
   DiaObject *obj;
   int i;
 
-  box = g_malloc0(sizeof(Box));
+  box = g_new0 (Box, 1);
   elem = &box->element;
   obj = &elem->object;
 
@@ -551,7 +551,7 @@ box_copy(Box *box)
 
   elem = &box->element;
 
-  newbox = g_malloc0(sizeof(Box));
+  newbox = g_new0 (Box, 1);
   newelem = &newbox->element;
   newobj = &newelem->object;
 
@@ -641,7 +641,7 @@ box_load(ObjectNode obj_node, int version, DiaContext *ctx)
   int i;
   AttributeNode attr;
 
-  box = g_malloc0(sizeof(Box));
+  box = g_new0 (Box, 1);
   elem = &box->element;
   obj = &elem->object;
 
diff --git a/objects/standard/ellipse.c b/objects/standard/ellipse.c
index ad7518371..ba96828f6 100644
--- a/objects/standard/ellipse.c
+++ b/objects/standard/ellipse.c
@@ -504,7 +504,7 @@ ellipse_create(Point *startpoint,
   DiaObject *obj;
   int i;
 
-  ellipse = g_malloc0(sizeof(Ellipse));
+  ellipse = g_new0 (Ellipse, 1);
   elem = &ellipse->element;
   obj = &elem->object;
 
@@ -564,7 +564,7 @@ ellipse_copy(Ellipse *ellipse)
 
   elem = &ellipse->element;
 
-  newellipse = g_malloc0(sizeof(Ellipse));
+  newellipse = g_new0 (Ellipse, 1);
   newelem = &newellipse->element;
   newobj = &newelem->object;
 
@@ -647,7 +647,7 @@ static DiaObject *ellipse_load(ObjectNode obj_node, int version, DiaContext *ctx
   int i;
   AttributeNode attr;
 
-  ellipse = g_malloc0(sizeof(Ellipse));
+  ellipse = g_new0 (Ellipse, 1);
   elem = &ellipse->element;
   obj = &elem->object;
 
diff --git a/objects/standard/image.c b/objects/standard/image.c
index c8727fb32..27d06d968 100644
--- a/objects/standard/image.c
+++ b/objects/standard/image.c
@@ -598,7 +598,7 @@ image_create(Point *startpoint,
   DiaObject *obj;
   int i;
 
-  image = g_malloc0(sizeof(Image));
+  image = g_new0 (Image, 1);
   elem = &image->element;
   obj = &elem->object;
 
@@ -669,7 +669,7 @@ image_copy(Image *image)
 
   elem = &image->element;
 
-  newimage = g_malloc0(sizeof(Image));
+  newimage = g_new0 (Image, 1);
   newelem = &newimage->element;
   newobj = &newelem->object;
 
diff --git a/objects/standard/line.c b/objects/standard/line.c
index 9ed28996c..ca23815ec 100644
--- a/objects/standard/line.c
+++ b/objects/standard/line.c
@@ -502,7 +502,7 @@ line_create(Point *startpoint,
 
   line_init_defaults();
 
-  line = g_malloc0(sizeof(Line));
+  line = g_new0 (Line, 1);
 
   line->line_width = attributes_get_default_linewidth();
   line->line_color = attributes_get_foreground();
@@ -551,7 +551,7 @@ line_copy(Line *line)
 
   conn = &line->connection;
 
-  newline = g_malloc0(sizeof(Line));
+  newline = g_new0 (Line, 1);
   newconn = &newline->connection;
   newobj = &newconn->object;
 
@@ -699,7 +699,7 @@ line_load(ObjectNode obj_node, int version, DiaContext *ctx)
   DiaObject *obj;
   AttributeNode attr;
 
-  line = g_malloc0(sizeof(Line));
+  line = g_new0 (Line, 1);
 
   conn = &line->connection;
   obj = &conn->object;
diff --git a/objects/standard/polygon.c b/objects/standard/polygon.c
index f668027c5..9024a10b1 100644
--- a/objects/standard/polygon.c
+++ b/objects/standard/polygon.c
@@ -320,7 +320,7 @@ polygon_copy(Polygon *polygon)
 
   poly = &polygon->poly;
 
-  newpolygon = g_malloc0(sizeof(Polygon));
+  newpolygon = g_new0 (Polygon, 1);
   newpoly = &newpolygon->poly;
 
   polyshape_copy(poly, newpoly);
@@ -400,7 +400,7 @@ polygon_load(ObjectNode obj_node, int version, DiaContext *ctx)
   DiaObject *obj;
   AttributeNode attr;
 
-  polygon = g_malloc0(sizeof(Polygon));
+  polygon = g_new0 (Polygon, 1);
 
   poly = &polygon->poly;
   obj = &poly->object;
diff --git a/objects/standard/polyline.c b/objects/standard/polyline.c
index 0f15467e7..7536b5df9 100644
--- a/objects/standard/polyline.c
+++ b/objects/standard/polyline.c
@@ -328,7 +328,7 @@ polyline_create(Point *startpoint,
   Point defaultlen = { 1.0, 1.0 };
 
   /*polyline_init_defaults();*/
-  polyline = g_malloc0(sizeof(Polyline));
+  polyline = g_new0 (Polyline, 1);
   poly = &polyline->poly;
   obj = &poly->object;
 
@@ -387,7 +387,7 @@ polyline_copy(Polyline *polyline)
 
   poly = &polyline->poly;
 
-  newpolyline = g_malloc0(sizeof(Polyline));
+  newpolyline = g_new0 (Polyline, 1);
   newpoly = &newpolyline->poly;
 
   polyconn_copy(poly, newpoly);
@@ -525,7 +525,7 @@ polyline_load(ObjectNode obj_node, int version, DiaContext *ctx)
   DiaObject *obj;
   AttributeNode attr;
 
-  polyline = g_malloc0(sizeof(Polyline));
+  polyline = g_new0 (Polyline, 1);
 
   poly = &polyline->poly;
   obj = &poly->object;
diff --git a/objects/standard/textobj.c b/objects/standard/textobj.c
index e2b2e850c..04a40b912 100644
--- a/objects/standard/textobj.c
+++ b/objects/standard/textobj.c
@@ -428,7 +428,7 @@ textobj_create(Point *startpoint,
   DiaFont *font = NULL;
   real font_height;
 
-  textobj = g_malloc0(sizeof(Textobj));
+  textobj = g_new0 (Textobj, 1);
   obj = &textobj->object;
   obj->enclosing_box = g_new0 (DiaRectangle, 1);
 
@@ -512,9 +512,9 @@ textobj_load(ObjectNode obj_node, int version, DiaContext *ctx)
   AttributeNode attr;
   Point startpoint = {0.0, 0.0};
 
-  textobj = g_malloc0(sizeof(Textobj));
+  textobj = g_new0 (Textobj, 1);
   obj = &textobj->object;
-  obj->enclosing_box = g_new0 (DiaRectangle,1);
+  obj->enclosing_box = g_new0 (DiaRectangle, 1);
 
   obj->type = &textobj_type;
   obj->ops = &textobj_ops;
diff --git a/objects/standard/zigzagline.c b/objects/standard/zigzagline.c
index 8e7833397..2a3323ae4 100644
--- a/objects/standard/zigzagline.c
+++ b/objects/standard/zigzagline.c
@@ -248,7 +248,7 @@ zigzagline_create(Point *startpoint,
   Point dummy = {0, 0};
 
   /*zigzagline_init_defaults();*/
-  zigzagline = g_malloc0(sizeof(Zigzagline));
+  zigzagline = g_new0 (Zigzagline, 1);
   orth = &zigzagline->orth;
   obj = &orth->object;
 
@@ -297,7 +297,7 @@ zigzagline_copy(Zigzagline *zigzagline)
 
   orth = &zigzagline->orth;
 
-  newzigzagline = g_malloc0(sizeof(Zigzagline));
+  newzigzagline = g_new0 (Zigzagline, 1);
   neworth = &newzigzagline->orth;
 
   orthconn_copy(orth, neworth);
@@ -539,7 +539,7 @@ zigzagline_load(ObjectNode obj_node, int version, DiaContext *ctx)
   DiaObject *obj;
   AttributeNode attr;
 
-  zigzagline = g_malloc0(sizeof(Zigzagline));
+  zigzagline = g_new0 (Zigzagline, 1);
 
   orth = &zigzagline->orth;
   obj = &orth->object;
diff --git a/plug-ins/dxf/dxf-import.c b/plug-ins/dxf/dxf-import.c
index ea730e515..a2a2ca6bf 100644
--- a/plug-ins/dxf/dxf-import.c
+++ b/plug-ins/dxf/dxf-import.c
@@ -431,7 +431,7 @@ read_entity_polyline_dxf (FILE *filedxf, DxfData *data, DiagramData *dia)
         if (!strcmp (data->value, "VERTEX")) {
           points++;
 
-          p = g_realloc (p, sizeof (Point) * points);
+          p = g_renew (Point, p, points);
 
           /*printf( "Vertex %d\n", points );*/
 
@@ -489,7 +489,7 @@ read_entity_polyline_dxf (FILE *filedxf, DxfData *data, DiagramData *dia)
     if (points == bulge_end && bulge_x_avail && bulge_y_avail) {
       /* turn the last segment into a bulge */
 
-      p = g_realloc (p, sizeof (Point) * (points + 10));
+      p = g_renew (Point, p, points + 10);
 
       if (points < 2)
           continue;
diff --git a/plug-ins/postscript/diapsrenderer.c b/plug-ins/postscript/diapsrenderer.c
index b89f7dd50..cbde440fc 100644
--- a/plug-ins/postscript/diapsrenderer.c
+++ b/plug-ins/postscript/diapsrenderer.c
@@ -600,7 +600,7 @@ ps_convert_string (const char *text, DiaContext *ctx)
   }
 
   /* Escape all '(' and ')':  */
-  buffer = g_malloc (2 * strlen (localestr) + 1);
+  buffer = g_new0 (char, 2 * strlen (localestr) + 1);
   *buffer = 0;
   str = localestr;
   while (*str != 0) {
diff --git a/plug-ins/postscript/paginate_psprint.c b/plug-ins/postscript/paginate_psprint.c
index 2c5e70ef1..ff1c29c13 100644
--- a/plug-ins/postscript/paginate_psprint.c
+++ b/plug-ins/postscript/paginate_psprint.c
@@ -349,7 +349,7 @@ diagram_print_ps (DiagramData *dia, const gchar* original_filename)
   /* Work out diagram filename and use this as default .ps file */
   filename = g_path_get_basename (original_filename);
 
-  printer_filename = g_malloc (strlen (filename) + 4);
+  printer_filename = g_new0 (char, strlen (filename) + 4);
   printer_filename = strcpy (printer_filename, filename);
   dot = strrchr (printer_filename, '.');
   if ((dot != NULL) && (strcmp (dot, ".dia") == 0)) {
diff --git a/plug-ins/svg/svg-import.c b/plug-ins/svg/svg-import.c
index 14cec92ec..2c92b795c 100644
--- a/plug-ins/svg/svg-import.c
+++ b/plug-ins/svg/svg-import.c
@@ -985,11 +985,11 @@ tmp++;
   xmlFree(str);
 
   /* If an odd number of coordinates is provided, then the element is in error, cut off below */
-  points = g_malloc0(arr->len/2*sizeof(Point));
+  points = g_new0 (Point, arr->len / 2);
 
-  pcd = g_new(MultipointCreateData, 1);
-  pcd->num_points = arr->len/2;
-  rarr = (real *)arr->data;
+  pcd = g_new0 (MultipointCreateData, 1);
+  pcd->num_points = arr->len / 2;
+  rarr = (double *) arr->data;
   for (i = 0; i < pcd->num_points; i++) {
     points[i].x = rarr[2*i];
     points[i].y = rarr[2*i+1];
diff --git a/plug-ins/vdx/vdx-export.c b/plug-ins/vdx/vdx-export.c
index 5163efeda..1eb8c9dcb 100644
--- a/plug-ins/vdx/vdx-export.c
+++ b/plug-ins/vdx/vdx-export.c
@@ -1509,7 +1509,7 @@ vdx_convert_xml_string(const char *s)
     if (strcspn(s, "&<>\"'") == strlen(s)) return s;
 
     /* Ensure we have enough space, even if all the string is quotes */
-    out = realloc(out, 6*strlen(s)+1);
+    out = g_renew (char, out, 6 * strlen (s) + 1);
     c = out;
 
     while(*s)
diff --git a/plug-ins/xfig/xfig-export.c b/plug-ins/xfig/xfig-export.c
index eaab91836..fb16695b4 100644
--- a/plug-ins/xfig/xfig-export.c
+++ b/plug-ins/xfig/xfig-export.c
@@ -490,7 +490,7 @@ figText(XfigRenderer *renderer, const guchar *text)
       newlen += 1;
     }
   }
-  returntext = g_malloc(sizeof(char)*(newlen+1));
+  returntext = g_new0 (char, newlen + 1);
   j = 0;
   for (i = 0; i < len; i++, j++) {
     if (text[i] > 127) {
diff --git a/plug-ins/xfig/xfig-import.c b/plug-ins/xfig/xfig-import.c
index 75af448e7..9741705d4 100644
--- a/plug-ins/xfig/xfig-import.c
+++ b/plug-ins/xfig/xfig-import.c
@@ -350,27 +350,33 @@ fig_fix_text(gchar *text) {
     }
 }
 
+
 static char *
-fig_read_text_line(FILE *file) {
-    char *text_buf;
-    guint text_alloc, text_len;
-
-    getc(file);
-    text_alloc = 80;
-    text_buf = (char *)g_malloc(text_alloc*sizeof(char));
-    text_len = 0;
-    while (fgets(text_buf+text_len, text_alloc-text_len, file) != NULL) {
-       if (strlen(text_buf) < text_alloc-1) break;
-       text_len = text_alloc;
-       text_alloc *= 2;
-       text_buf = (char *)g_realloc(text_buf, text_alloc*sizeof(char));
+fig_read_text_line (FILE *file)
+{
+  char *text_buf;
+  guint text_alloc, text_len;
+
+  getc (file);
+  text_alloc = 80;
+  text_buf = g_new0 (char, text_alloc);
+  text_len = 0;
+
+  while (fgets (text_buf + text_len, text_alloc - text_len, file) != NULL) {
+    if (strlen (text_buf) < text_alloc-1) {
+      break;
     }
+    text_len = text_alloc;
+    text_alloc *= 2;
+    text_buf = g_renew (char, text_buf, text_alloc);
+  }
 
-    text_buf = fig_fix_text(text_buf);
+  text_buf = fig_fix_text (text_buf);
 
-    return text_buf;
+  return text_buf;
 }
 
+
 static GList *depths[FIG_MAX_DEPTHS];
 
 /* If there's something in the compound stack, we ignore the depth field,
diff --git a/plug-ins/xslt/xslt.c b/plug-ins/xslt/xslt.c
index 0621487b9..606b41901 100644
--- a/plug-ins/xslt/xslt.c
+++ b/plug-ins/xslt/xslt.c
@@ -191,7 +191,7 @@ read_implementations (xmlNodePtr cur, gchar *path)
       cur = cur->next;
       continue;
     }
-    to = g_malloc (sizeof (toxsl_t));
+    to = g_new0 (toxsl_t, 1);
     to->next = NULL;
     to->name = (gchar *) xmlGetProp (cur, (const xmlChar *) "name");
     to->xsl = (gchar *) xmlGetProp (cur, (const xmlChar *) "stylesheet");


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