/* crypto/lhash/lhash.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* [including the GNU Public Licence.]
*/
-char *lh_version="lhash part of SSLeay 0.8.1b 29-Jun-1998";
+char *lh_version="lhash part of OpenSSL 0.9.2 31-Dec-1998";
/* Code for dynamic hash table routines
* Author - Eric Young v 2.0
*
+ * 2.2 eay - added #include "crypto.h" so the memory leak checking code is
+ * present. eay 18-Jun-98
+ *
+ * 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98
+ *
* 2.0 eay - Fixed a bug that occured when using lh_delete
* from inside lh_doall(). As entries were deleted,
* the 'table' was 'contract()ed', making some entries
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include "crypto.h"
#include "lhash.h"
#undef MIN_NODES
LHASH *ret;
int i;
- if ((ret=(LHASH *)malloc(sizeof(LHASH))) == NULL)
+ if ((ret=(LHASH *)Malloc(sizeof(LHASH))) == NULL)
goto err0;
- if ((ret->b=(LHASH_NODE **)malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
+ if ((ret->b=(LHASH_NODE **)Malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
goto err1;
for (i=0; i<MIN_NODES; i++)
ret->b[i]=NULL;
ret->num_retrieve_miss=0;
ret->num_hash_comps=0;
+ ret->error=0;
return(ret);
err1:
- free((char *)ret);
+ Free((char *)ret);
err0:
return(NULL);
}
unsigned int i;
LHASH_NODE *n,*nn;
+ if(lh == NULL)
+ return;
+
for (i=0; i<lh->num_nodes; i++)
{
n=lh->b[i];
while (n != NULL)
{
nn=n->next;
- free(n);
+ Free(n);
n=nn;
}
}
- free((char *)lh->b);
- free((char *)lh);
+ Free((char *)lh->b);
+ Free((char *)lh);
}
char *lh_insert(lh, data)
LHASH_NODE *nn,**rn;
char *ret;
+ lh->error=0;
if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))
expand(lh);
if (*rn == NULL)
{
- if ((nn=(LHASH_NODE *)malloc(sizeof(LHASH_NODE))) == NULL)
+ if ((nn=(LHASH_NODE *)Malloc(sizeof(LHASH_NODE))) == NULL)
+ {
+ lh->error++;
return(NULL);
+ }
nn->data=data;
nn->next=NULL;
#ifndef NO_HASH_COMP
LHASH_NODE *nn,**rn;
char *ret;
+ lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
nn= *rn;
*rn=nn->next;
ret=nn->data;
- free((char *)nn);
+ Free((char *)nn);
lh->num_delete++;
}
LHASH_NODE **rn;
char *ret;
+ lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
if ((lh->p) >= lh->pmax)
{
j=(int)lh->num_alloc_nodes*2;
- n=(LHASH_NODE **)realloc((char *)lh->b,
+ n=(LHASH_NODE **)Realloc((char *)lh->b,
(unsigned int)sizeof(LHASH_NODE *)*j);
if (n == NULL)
{
/* fputs("realloc error in lhash",stderr); */
+ lh->error++;
lh->p=0;
return;
}
lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
if (lh->p == 0)
{
- n=(LHASH_NODE **)realloc((char *)lh->b,
+ n=(LHASH_NODE **)Realloc((char *)lh->b,
(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
if (n == NULL)
{
/* fputs("realloc error in lhash",stderr); */
+ lh->error++;
return;
}
lh->num_contract_reallocs++;