summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobert James Kaes <rjkaes@users.sourceforge.net>2001-09-07 00:38:03 +0000
committerRobert James Kaes <rjkaes@users.sourceforge.net>2001-09-07 00:38:03 +0000
commitc24cace1d1182b0526133fd7ff06b420f49c2ab1 (patch)
treef8a840b4fe890d2daf92870234d327e4f4870ba3 /src
parent32ce57a6f67ddc6e9af30461e4bcead1509d99ca (diff)
Fixed the ternary_destroy() function which causes segfaults.
Diffstat (limited to 'src')
-rw-r--r--src/ternary.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/ternary.c b/src/ternary.c
index 9ced4d9..a118425 100644
--- a/src/ternary.c
+++ b/src/ternary.c
@@ -1,4 +1,4 @@
-/* $Id: ternary.c,v 1.8 2001-09-06 21:52:31 rjkaes Exp $
+/* $Id: ternary.c,v 1.9 2001-09-07 00:38:03 rjkaes Exp $
*
* This module creates a Ternary Search Tree which can store both string
* keys, and arbitrary data for each key. It works similar to a hash, and
@@ -41,7 +41,7 @@
/*
* Macros for the tree structures (limits)
*/
-#define MAXTREES 1024 /* max. number of trees */
+#define MAXTREES 128 /* max. number of trees */
/*
* The structure for each individual node of the ternary tree.
@@ -54,8 +54,8 @@ typedef struct tnode {
/*
* The structure for each root of a ternary tree.
*/
-#define BUFSIZE 1000
-#define BUFARRAY 10000
+#define BUFSIZE 1024
+#define BUFARRAY 1024
typedef struct ttree {
TERNARY token; /* contains unique ternary tree ID */
Tnode *tree_root;
@@ -257,6 +257,7 @@ int ternary_destroy(TERNARY tno, void (*freeptr)(void *))
{
int cur; /* index of current tree */
unsigned int i, j;
+ Tnode *ptr;
/*
* Check that tno refers to an existing tree;
@@ -267,17 +268,18 @@ int ternary_destroy(TERNARY tno, void (*freeptr)(void *))
for (i = 0; i < trees[cur]->freen; i++) {
for (j = 0; j < BUFSIZE; j++) {
- Tnode *ptr = (trees[cur]->freearr[i] + j);
+ DEBUG2("first: j = %d, i = %d", j, i);
+
+ ptr = (trees[cur]->freearr[i] + j);
if (ptr->splitchar == 0)
if (freeptr)
(*freeptr)(ptr->eqkid);
- safefree(ptr);
}
+ safefree(trees[cur]->freearr[i]);
}
- trees[cur]->token = 0;
- trees[cur]->tree_root = trees[cur]->buf = NULL;
- trees[cur]->bufn = trees[cur]->freen = 0;
+ /* Remove the tree and NULL it's position in the array */
+ safefree(trees[cur]);
return TE_NONE;
}