From 273a0e4257d9283e2aea8e4e035010f9d8995ced Mon Sep 17 00:00:00 2001 From: Donald Caldwell Date: Thu, 29 Sep 2011 14:27:49 -0400 Subject: [PATCH] memory leak in index.c RTreeClose the rtree root node had not been freed when the rtree was closed --- lib/label/index.c | 19 ++++++++++++++----- lib/label/node.c | 7 +++---- lib/label/xlabels.c | 7 +++---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/label/index.c b/lib/label/index.c index ceefc6c0e..d3b673265 100644 --- a/lib/label/index.c +++ b/lib/label/index.c @@ -22,8 +22,10 @@ LeafList_t *RTreeNewLeafList(Leaf_t * lp) { LeafList_t *llp; - if ((llp = NEW(LeafList_t))) + if ((llp = NEW(LeafList_t))) { llp->leaf = lp; + llp->next = 0; + } return llp; } @@ -46,6 +48,7 @@ void RTreeLeafListFree(LeafList_t * llp) free(llp); llp = tlp; } + free(llp); return; } @@ -118,9 +121,13 @@ static int RTreeClose2(RTree_t * rtp, Node_t * n) for (i = 0; i < NODECARD; i++) { if (!n->branch[i].child) continue; + // free(n->branch[i].child); DisconBranch(n, i); rtp->EntryCount--; + if (rtp->StatFlag) + rtp->ElimCount++; } + //free(n); } return 0; } @@ -129,6 +136,7 @@ static int RTreeClose2(RTree_t * rtp, Node_t * n) int RTreeClose(RTree_t * rtp) { RTreeClose2(rtp, rtp->root); + free(rtp->root); free(rtp); return 0; } @@ -231,7 +239,7 @@ RTreeInsert(RTree_t * rtp, Rect_t * r, void *data, Node_t ** n, int level) /* RTreeInsert(RTree_t*rtp, Rect_t*r, int data, Node_t**n, int level) { */ register int i; register Node_t *newroot; - Node_t *newnode; + Node_t *newnode=0; Branch_t b; int result = 0; @@ -272,6 +280,7 @@ RTreeInsert(RTree_t * rtp, Rect_t * r, void *data, Node_t ** n, int level) b.child = newnode; AddBranch(rtp, &b, newroot, NULL); *n = newroot; + // rtp->root = newroot; rtp->EntryCount += 2; result = 1; } @@ -295,9 +304,9 @@ RTreeInsert2(RTree_t * rtp, Rect_t * r, void *data, /* RTreeInsert2(RTree_t*rtp, Rect_t*r, int data, Node_t*n, Node_t**new, int level) { */ - register int i; + register int i=0; Branch_t b; - Node_t *n2; + Node_t *n2=0; assert(r && n && new); assert(level >= 0 && level <= n->level); @@ -466,7 +475,7 @@ RTreeDelete2(RTree_t * rtp, Rect_t * r, void *data, Node_t * n, */ struct ListNode *NewListNode() { - return (struct ListNode *) malloc(sizeof(struct ListNode)); + return (struct ListNode *) NEW(sizeof(struct ListNode)); } #endif diff --git a/lib/label/node.c b/lib/label/node.c index 4af16361c..0285ca03b 100644 --- a/lib/label/node.c +++ b/lib/label/node.c @@ -119,12 +119,11 @@ Rect_t NodeCover(Node_t * n) */ int PickBranch(Rect_t * r, Node_t * n) { - register Rect_t *rr; - register int i, flag, increase, bestIncr, area, bestArea; - int best; + register Rect_t *rr=0; + register int i=0, flag=1, increase=0, bestIncr=0, area=0, bestArea=0; + int best=0; assert(r && n); - flag = 1; for (i = 0; i < NODECARD; i++) { if (n->branch[i].child) { Rect_t rect; diff --git a/lib/label/xlabels.c b/lib/label/xlabels.c index e2d13e422..3fdc33eef 100644 --- a/lib/label/xlabels.c +++ b/lib/label/xlabels.c @@ -606,19 +606,18 @@ static int xlhdxload(XLabels_t * xlp) static int xlspdxload(XLabels_t * xlp) { - HDict_t *op; + HDict_t *op=0; for (op = dtfirst(xlp->hdx); op; op = dtnext(xlp->hdx, op)) { /* tree rectangle data node lvl */ - RTreeInsert(xlp->spdx, &op->d.rect, op->d.data, &xlp->spdx->root, - 0); + RTreeInsert(xlp->spdx, &op->d.rect, op->d.data, &xlp->spdx->root, 0); } return 0; } static int xlinitialize(XLabels_t * xlp) { - int r; + int r=0; if ((r = xlhdxload(xlp)) < 0) return r; if ((r = xlspdxload(xlp)) < 0) -- 2.40.0