Browse Source

htable: use system malloc for temporary allocation of hash table realod slots

- copes better with large number of slots, without a need to use shm
Daniel-Constantin Mierla 11 years ago
parent
commit
13626ccffe
1 changed files with 15 additions and 2 deletions
  1. 15 2
      modules/htable/htable.c

+ 15 - 2
modules/htable/htable.c

@@ -490,7 +490,8 @@ static struct mi_root* ht_mi_reload(struct mi_root* cmd_tree, void* param)
 		return init_mi_tree( 500, "no such hash table", 18);
 		return init_mi_tree( 500, "no such hash table", 18);
 	}
 	}
 	memcpy(&nht, ht, sizeof(ht_t));
 	memcpy(&nht, ht, sizeof(ht_t));
-	nht.entries = (ht_entry_t*)pkg_malloc(nht.htsize*sizeof(ht_entry_t));
+	/* it's temporary operation - use system malloc */
+	nht.entries = (ht_entry_t*)malloc(nht.htsize*sizeof(ht_entry_t));
 	if(nht.entries == NULL)
 	if(nht.entries == NULL)
 	{
 	{
 		ht_db_close_con();
 		ht_db_close_con();
@@ -500,6 +501,18 @@ static struct mi_root* ht_mi_reload(struct mi_root* cmd_tree, void* param)
 
 
 	if(ht_db_load_table(&nht, &ht->dbtable, 0)<0)
 	if(ht_db_load_table(&nht, &ht->dbtable, 0)<0)
 	{
 	{
+		/* free any entry set if it was a partial load */
+		for(i=0; i<nht.htsize; i++)
+		{
+			first = nht.entries[i].first;
+			while(first)
+			{
+				it = first;
+				first = first->next;
+				ht_cell_free(it);
+			}
+		}
+		free(nht.entries);
 		ht_db_close_con();
 		ht_db_close_con();
 		return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
 		return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
 	}
 	}
@@ -525,7 +538,7 @@ static struct mi_root* ht_mi_reload(struct mi_root* cmd_tree, void* param)
 			ht_cell_free(it);
 			ht_cell_free(it);
 		}
 		}
 	}
 	}
-	pkg_free(nht.entries);
+	free(nht.entries);
 	ht_db_close_con();
 	ht_db_close_con();
 	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
 	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
 }
 }