summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2013-06-26 20:06:50 +0000
committerXavier Roche <xroche@users.noreply.github.com>2013-06-26 20:06:50 +0000
commita835ee13e3f5a095467e645bd1ddea5ee208599e (patch)
treed7412dd6f882ee6b55f97a3b74c6d56705ca7ccc
parentb5e663cd80904d70ad2f0d6202a0c3ce6e582b58 (diff)
Fixed old 3-hashtable missing free on exit
Always use default starting hash size
-rw-r--r--src/htsback.c2
-rw-r--r--src/htscore.c38
-rw-r--r--src/htscoremain.c2
-rw-r--r--src/htsglobal.h4
-rw-r--r--src/htshash.c9
-rw-r--r--src/htshash.h3
-rw-r--r--src/htsindex.c2
-rw-r--r--src/htsserver.c6
-rw-r--r--src/htstools.c2
-rw-r--r--src/proxy/store.c6
10 files changed, 24 insertions, 50 deletions
diff --git a/src/htsback.c b/src/htsback.c
index e270d81..54c0637 100644
--- a/src/htsback.c
+++ b/src/htsback.c
@@ -80,7 +80,7 @@ struct_back *back_new(int back_max) {
sback->count = back_max;
sback->lnk = (lien_back *) calloct((back_max + 1), sizeof(lien_back));
- sback->ready = inthash_new(32767);
+ sback->ready = inthash_new(0);
sback->ready_size_bytes = 0;
inthash_value_is_malloc(sback->ready, 1);
// init
diff --git a/src/htscore.c b/src/htscore.c
index 2442524..fd4e9ff 100644
--- a/src/htscore.c
+++ b/src/htscore.c
@@ -172,6 +172,7 @@ RUN_CALLBACK0(opt, end); \
if (template_header) { freet(template_header); template_header=NULL; } \
if (template_body) { freet(template_body); template_body=NULL; } \
if (template_footer) { freet(template_footer); template_footer=NULL; } \
+ hash_free(&hash); \
clearCallbacks(&opt->state.callbacks); \
/*structcheck_init(-1);*/ \
} while(0)
@@ -263,7 +264,7 @@ int httpmirror(char *url1, httrackp * opt) {
int lien_tot = 0; // nombre de liens pour le moment
lien_url **liens = NULL; // les pointeurs sur les liens
hash_struct hash; // système de hachage, accélère la recherche dans les liens
- hash_struct *hashptr = &hash;
+ hash_struct *const hashptr = &hash;
t_cookie BIGSTK cookie; // gestion des cookies
int lien_max = 0;
size_t lien_size = 0; // octets restants dans buffer liens dispo
@@ -314,7 +315,6 @@ int httpmirror(char *url1, httrackp * opt) {
robots_wizard BIGSTK robots; // gestion robots.txt
inthash cache_hashtable = NULL;
inthash cache_tests = NULL;
- int cache_hash_size = 0;
//
char *template_header = NULL, *template_body = NULL, *template_footer = NULL;
@@ -397,10 +397,8 @@ int httpmirror(char *url1, httrackp * opt) {
cache.ptr_ant = cache.ptr_last = 0; // pointeur pour anticiper
// initialiser hash cache
- if (!cache_hash_size)
- cache_hash_size = HTS_HASH_SIZE;
- cache_hashtable = inthash_new(cache_hash_size);
- cache_tests = inthash_new(cache_hash_size);
+ cache_hashtable = inthash_new(0);
+ cache_tests = inthash_new(0);
if (cache_hashtable == NULL || cache_tests == NULL) {
printf("PANIC! : Not enough memory [%d]\n", __LINE__);
filters[0] = NULL; // uniquement a cause du warning de XH_extuninit
@@ -2196,34 +2194,6 @@ int httpmirror(char *url1, httrackp * opt) {
cache.zipOutput = NULL;
}
}
-#if DEBUG_HASH
- // noter les collisions
- {
- int i;
- int empty1 = 0, empty2 = 0, empty3 = 0;
-
- for(i = 0; i < HTS_HASH_SIZE; i++) {
- if (hash.hash[0][i] == -1)
- empty1++;
- if (hash.hash[1][i] == -1)
- empty2++;
- if (hash.hash[2][i] == -1)
- empty3++;
- }
- printf("\n");
- printf("Debug info: Hash-table report\n");
- printf("Number of files entered: %d\n", hashnumber);
- printf("Table size: %d\n", HTS_HASH_SIZE);
- printf("\n");
- printf("Longest chain sav: %d, empty: %d\n", longest_hash[0],
- empty1);
- printf("Longest chain adr,fil: %d, empty: %d\n", longest_hash[1],
- empty2);
- printf("Longest chain former_adr/fil: %d, empty: %d\n", longest_hash[2],
- empty3);
- printf("\n");
- }
-#endif
// fin afficher résumé dans log
// ending
diff --git a/src/htscoremain.c b/src/htscoremain.c
index 4a1bdcd..c5ebe77 100644
--- a/src/htscoremain.c
+++ b/src/htscoremain.c
@@ -1931,7 +1931,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) {
int found = 0;
char *filter = NULL;
cache_back cache;
- inthash cache_hashtable = inthash_new(HTS_HASH_SIZE);
+ inthash cache_hashtable = inthash_new(0);
int backupXFR = htsMemoryFastXfr;
int sendb = 0;
diff --git a/src/htsglobal.h b/src/htsglobal.h
index 2be342f..32a5a3e 100644
--- a/src/htsglobal.h
+++ b/src/htsglobal.h
@@ -246,15 +246,11 @@ Please visit our Website: http://www.httrack.com
#endif
#if HTS_SPARE_MEMORY==0
-/* Gestion des tables de hashage */
-#define HTS_HASH_SIZE 20147
/* Taille max d'une URL */
#define HTS_URLMAXSIZE 1024
/* Taille max ligne de commande (>=HTS_URLMAXSIZE*2) */
#define HTS_CDLMAXSIZE 1024
#else
-/* Gestion des tables de hashage */
-#define HTS_HASH_SIZE 1023
/* Taille max d'une URL */
#define HTS_URLMAXSIZE 256
/* Taille max ligne de commande (>=HTS_URLMAXSIZE*2) */
diff --git a/src/htshash.c b/src/htshash.c
index 1ac20ee..daf987c 100644
--- a/src/htshash.c
+++ b/src/htshash.c
@@ -57,7 +57,6 @@ Please visit our Website: http://www.httrack.com
// GESTION DES TABLES DE HACHAGE
// Méthode à 2 clés (adr+fil), 2e cle facultative
// hash[no_enregistrement][pos]->hash est un index dans le tableau général liens
-// #define HTS_HASH_SIZE 8191 (premier si possible!)
// type: numero enregistrement - 0 est case insensitive (sav) 1 (adr+fil) 2 (former_adr+former_fil)
// recherche dans la table selon nom1,nom2 et le no d'enregistrement
@@ -67,6 +66,14 @@ void hash_init(hash_struct * hash) {
hash->former_adrfil = inthash_new(0);
}
+void hash_free(hash_struct *hash) {
+ if (hash != NULL) {
+ inthash_delete(&hash->sav);
+ inthash_delete(&hash->adrfil);
+ inthash_delete(&hash->former_adrfil);
+ }
+}
+
static char * normalize_key(const char *nom1, const char *nom2,
hash_struct_type type, int normalized,
char *normfil_, char *catbuff) {
diff --git a/src/htshash.h b/src/htshash.h
index 62ea118..97b35ab 100644
--- a/src/htshash.h
+++ b/src/htshash.h
@@ -52,7 +52,8 @@ typedef enum hash_struct_type {
} hash_struct_type;
// tables de hachage
-void hash_init(hash_struct * hash);
+void hash_init(hash_struct *hash);
+void hash_free(hash_struct *hash);
int hash_read(const hash_struct * hash, const char *nom1, const char *nom2,
hash_struct_type type, int normalized);
void hash_write(hash_struct * hash, int lpos, int normalized);
diff --git a/src/htsindex.c b/src/htsindex.c
index 1fa453e..30fe59a 100644
--- a/src/htsindex.c
+++ b/src/htsindex.c
@@ -197,7 +197,7 @@ int index_keyword(const char *html_data, LLint size, const char *mime,
// Create hash structure
// Hash tables rulez da world!
- WordIndexHash = inthash_new(WordIndexSize);
+ WordIndexHash = inthash_new(0);
if (!WordIndexHash)
return 0;
diff --git a/src/htsserver.c b/src/htsserver.c
index 3559e3e..032ce53 100644
--- a/src/htsserver.c
+++ b/src/htsserver.c
@@ -1443,7 +1443,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) {
int htslang_init(void) {
if (NewLangList == NULL) {
- NewLangList = inthash_new(NewLangListSz);
+ NewLangList = inthash_new(0);
if (NewLangList == NULL) {
abortLog("Error in lang.h: not enough memory");
} else {
@@ -1486,8 +1486,8 @@ static int htslang_load(char *limit_to, char *path) {
//
if (!limit_to) {
LANG_DELETE();
- NewLangStr = inthash_new(NewLangStrSz);
- NewLangStrKeys = inthash_new(NewLangStrKeysSz);
+ NewLangStr = inthash_new(0);
+ NewLangStrKeys = inthash_new(0);
if ((NewLangStr == NULL) || (NewLangStrKeys == NULL)) {
abortLog("Error in lang.h: not enough memory");
} else {
diff --git a/src/htstools.c b/src/htstools.c
index 77fa70e..255a1a2 100644
--- a/src/htstools.c
+++ b/src/htstools.c
@@ -990,7 +990,7 @@ HTSEXT_API char *hts_getcategories(char *path, int type) {
String iname = STRING_EMPTY;
if (type == 1) {
- hashCateg = inthash_new(127);
+ hashCateg = inthash_new(0);
StringCat(categ, "Test category 1");
StringCat(categ, "\r\nTest category 2");
}
diff --git a/src/proxy/store.c b/src/proxy/store.c
index 4ad4a0c..1b9e9f2 100644
--- a/src/proxy/store.c
+++ b/src/proxy/store.c
@@ -234,7 +234,7 @@ struct _PT_Cache {
PT_Indexes PT_New(void) {
PT_Indexes index = (PT_Indexes) calloc(sizeof(_PT_Indexes), 1);
- index->cil = inthash_new(127);
+ index->cil = inthash_new(0);
index->index_size = 0;
index->index = NULL;
return index;
@@ -432,7 +432,7 @@ char **PT_Enumerate(PT_Indexes indexes, const char *url, int subtree) {
inthash hdupes = NULL;
if (!subtree)
- hdupes = inthash_new(127);
+ hdupes = inthash_new(0);
StringClear(list);
StringClear(listindexes);
StringClear(subitem);
@@ -549,7 +549,7 @@ PT_Index PT_LoadCache(const char *filename) {
index->type = type;
index->slots.common.timestamp = (time_t) time(NULL);
index->slots.common.startUrl[0] = '\0';
- index->slots.common.hash = inthash_new(8191);
+ index->slots.common.hash = inthash_new(0);
if (!_IndexFuncts[type].PT_LoadCache(index, filename)) {
proxytrack_print_log(DEBUG,
"reading httrack cache (format #%d) %s : error",