Browse code

- fixed bug in list handling (del)

Andrei Pelinescu-Onciul authored on 04/09/2007 10:01:27
Showing 2 changed files
... ...
@@ -77,7 +77,7 @@ MAIN_NAME=ser
77 77
 VERSION = 2
78 78
 PATCHLEVEL = 1
79 79
 SUBLEVEL =  0
80
-EXTRAVERSION = -dev10
80
+EXTRAVERSION = -dev11
81 81
 
82 82
 SER_VER = $(shell expr $(VERSION) \* 1000000 + $(PATCHLEVEL) \* 1000 + \
83 83
 			$(SUBLEVEL) )
... ...
@@ -333,7 +333,6 @@ void destroy_dst_blacklist()
333 333
 {
334 334
 	int r;
335 335
 	struct dst_blst_entry** crt;
336
-	struct dst_blst_entry** tmp;
337 336
 	struct dst_blst_entry* e;
338 337
 
339 338
 	if (blst_timer_h){
... ...
@@ -360,11 +359,11 @@ void destroy_dst_blacklist()
360 359
 
361 360
 	if (dst_blst_hash){
362 361
 		for(r=0; r<DST_BLST_HASH_SIZE; r++){
363
-			for (crt=&dst_blst_hash[r].first, tmp=&(*crt)->next; *crt;
364
-					crt=tmp, tmp=&(*crt)->next){
365
-			e=*crt;
366
-			*crt=(*crt)->next;
367
-			blst_destroy_entry(e);
362
+			crt=&dst_blst_hash[r].first;
363
+			while(*crt){
364
+				e=*crt;
365
+				*crt=(*crt)->next;
366
+				blst_destroy_entry(e);
368 367
 			}
369 368
 		}
370 369
 		shm_free(dst_blst_hash);
... ...
@@ -520,6 +519,7 @@ inline static struct dst_blst_entry* _dst_blacklist_lst_find(
520 519
 		/* remove old expired entries */
521 520
 		if ((s_ticks_t)(now-(*crt)->expire)>=0){
522 521
 			*crt=(*crt)->next;
522
+			tmp=crt;
523 523
 			*blst_mem_used-=DST_BLST_ENTRY_SIZE(*e);
524 524
 			BLST_HASH_STATS_DEC(hash);
525 525
 			blst_destroy_entry(e);
... ...
@@ -560,6 +560,7 @@ inline static int _dst_blacklist_del(
560 560
 		/* remove old expired entries */
561 561
 		if ((s_ticks_t)(now-(*crt)->expire)>=0){
562 562
 			*crt=(*crt)->next;
563
+			tmp=crt;
563 564
 			*blst_mem_used-=DST_BLST_ENTRY_SIZE(*e);
564 565
 			BLST_HASH_STATS_DEC(hash);
565 566
 			blst_destroy_entry(e);
... ...
@@ -568,6 +569,7 @@ inline static int _dst_blacklist_del(
568 569
 					(e->proto==proto)) && 
569 570
 					(memcmp(ip->u.addr, e->ip, ip->len)==0)){
570 571
 			*crt=(*crt)->next;
572
+			tmp=crt;
571 573
 			*blst_mem_used-=DST_BLST_ENTRY_SIZE(*e);
572 574
 			BLST_HASH_STATS_DEC(hash);
573 575
 			blst_destroy_entry(e);
... ...
@@ -616,6 +618,7 @@ inline static int dst_blacklist_clean_expired(unsigned int target,
616 618
 				prefetch_loc_r((*crt)->next, 1);
617 619
 				if ((s_ticks_t)(now+delta-(*crt)->expire)>=0){
618 620
 					*crt=(*crt)->next;
621
+					tmp=crt;
619 622
 					*blst_mem_used-=DST_BLST_ENTRY_SIZE(*e);
620 623
 					blst_destroy_entry(e);
621 624
 					BLST_HASH_STATS_DEC(i);
... ...
@@ -1003,24 +1006,23 @@ void dst_blst_flush(void)
1003 1006
 {
1004 1007
 	int h;
1005 1008
 	struct dst_blst_entry* e;
1006
-	struct dst_blst_entry** last;
1009
+	struct dst_blst_entry** crt;
1010
+	struct dst_blst_entry** tmp;
1007 1011
 
1008 1012
 	for(h=0; h<DST_BLST_HASH_SIZE; h++){
1009 1013
 		LOCK_BLST(h);
1010
-		last = &dst_blst_hash[h].first;
1011
-		for(e=dst_blst_hash[h].first; e; e=e->next){
1012
-			if (e->flags & BLST_PERMANENT) {
1013
-				/* permanent entry, do not remove it from the list */
1014
-				*last = e;
1015
-				last = &e->next;
1016
-			} else {
1017
-				/* remove the entry from the list */
1014
+		for (crt=&dst_blst_hash[h].first, tmp=&(*crt)->next;
1015
+				*crt; crt=tmp, tmp=&(*crt)->next){
1016
+			e=*crt;
1017
+			prefetch_loc_r((*crt)->next, 1);
1018
+			if (!(e->flags &  BLST_PERMANENT)){
1019
+				*crt=(*crt)->next;
1020
+				tmp=crt;
1018 1021
 				*blst_mem_used-=DST_BLST_ENTRY_SIZE(*e);
1019 1022
 				blst_destroy_entry(e);
1020 1023
 				BLST_HASH_STATS_DEC(h);
1021 1024
 			}
1022 1025
 		}
1023
-		*last = NULL;
1024 1026
 		UNLOCK_BLST(h);
1025 1027
 	}
1026 1028
 }