[dia] [scan-build] Dereference of null pointer



commit 12fe0b4b9830c45ba6ce59dd1abb41058ac7d8ed
Author: Hans Breuer <hans breuer org>
Date:   Wed Jun 29 22:57:52 2011 +0200

    [scan-build] Dereference of null pointer
    
    Probably not.But going to stack allocation from malloc
    to a never freed static pointer at least plugs the
    static leak. Also needs less lines of code.

 objects/Misc/tree.c   |   16 ++++------------
 objects/network/bus.c |   16 ++++------------
 2 files changed, 8 insertions(+), 24 deletions(-)
---
diff --git a/objects/Misc/tree.c b/objects/Misc/tree.c
index 9b413ab..c7553af 100644
--- a/objects/Misc/tree.c
+++ b/objects/Misc/tree.c
@@ -200,24 +200,16 @@ tree_move_handle(Tree *tree, Handle *handle,
 {
   Connection *conn = &tree->connection;
   Point *endpoints;
-  static real *parallel=NULL;
-  static real *perp=NULL;
-  static int max_num=0;
+  real *parallel;
+  real *perp;
   Point vhat, vhatperp;
   Point u;
   real vlen, vlen2;
   real len_scale;
   int i;
 
-  if (tree->num_handles>max_num) {
-    if (parallel!=NULL) {
-      g_free(parallel);
-      g_free(perp);
-    }
-    parallel = g_malloc(sizeof(real)*tree->num_handles);
-    perp = g_malloc(sizeof(real)*tree->num_handles);
-    max_num = tree->num_handles;
-  }
+  parallel = (real *)g_alloca (tree->num_handles * sizeof(real));
+  perp = (real *)g_alloca (tree->num_handles * sizeof(real));
 
   if (handle->id == HANDLE_BUS) {
     handle->pos = *to;
diff --git a/objects/network/bus.c b/objects/network/bus.c
index 4a522a6..7648e3d 100644
--- a/objects/network/bus.c
+++ b/objects/network/bus.c
@@ -208,24 +208,16 @@ bus_move_handle(Bus *bus, Handle *handle,
 {
   Connection *conn = &bus->connection;
   Point *endpoints;
-  static real *parallel=NULL;
-  static real *perp=NULL;
-  static int max_num=0;
+  real *parallel=NULL;
+  real *perp=NULL;
   Point vhat, vhatperp;
   Point u;
   real vlen, vlen2;
   real len_scale;
   int i;
 
-  if (bus->num_handles>max_num) {
-    if (parallel!=NULL) {
-      g_free(parallel);
-      g_free(perp);
-    }
-    parallel = g_malloc(sizeof(real)*bus->num_handles);
-    perp = g_malloc(sizeof(real)*bus->num_handles);
-    max_num = bus->num_handles;
-  }
+  parallel = (real *)g_alloca (bus->num_handles * sizeof(real));
+  perp = (real *)g_alloca (bus->num_handles * sizeof(real));
 
   if (handle->id == HANDLE_BUS) {
     handle->pos = *to;



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