samba-vscan/global vscan-fileaccesslog.c,1.8.2.1,1.8.2.2

[email protected]
Newsgroups gmane.comp.security.virus.openantivirus.cvs
Message-ID <[email protected]>
Update of /cvsroot/openantivirus/samba-vscan/global
In directory sc8-pr-cvs1:/tmp/cvs-serv20580

Modified Files:
      Tag: VSCAN_0_3
	vscan-fileaccesslog.c 
Log Message:
bugfix: counter was not always decreased when entry was deleted. use
ZERO_STRUCTP instead of ZERO_STRUCT. Patch by Moritz Both


Index: vscan-fileaccesslog.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/global/vscan-fileaccesslog.c,v
retrieving revision 1.8.2.1
retrieving revision 1.8.2.2
diff -u -d -r1.8.2.1 -r1.8.2.2
--- vscan-fileaccesslog.c	14 Jul 2003 13:09:15 -0000	1.8.2.1
+++ vscan-fileaccesslog.c	6 Nov 2003 14:30:59 -0000	1.8.2.2
@@ -37,6 +37,26 @@
 static int lrufiles_max_entries = MAX_LRUFILES;
 static time_t lrufiles_invalidate_time = LRUFILES_INVALIDATE_TIME;
 
+
+/** Delete an entry from the lrufile list given by pointer. The
+ * entry must be in the list (this is not checked).
+ * @param entry The entry to be deleted
+ */
+static void lrufiles_delete_p(struct lrufiles_struct *entry)
+{
+	DEBUG(10, ("removing entry from lrufiles list: '%s'\n",
+			entry->fname));
+	/* should the last entry be deleted? If yes, set LrufilesEnd pointer */
+	if ( LrufilesEnd == entry )
+		LrufilesEnd = entry->prev;
+	DLIST_REMOVE(Lrufiles, entry);
+	ZERO_STRUCTP(entry);
+	SAFE_FREE(entry);
+	lrufiles_count--;
+	DEBUG(10, ("entry deleted, %d left in list\n", lrufiles_count));
+
+}
+
 /** 
  * initialise the double-linked list 
  * @param max_entries		specifies the maximum number of entries, if 0
@@ -145,12 +165,11 @@
 			DEBUG(10, ("lru maximum reached '%d'\n", lrufiles_count));
 			/* remove the first one - it really removes only the first one */
 			tmp = Lrufiles;
-			DLIST_REMOVE(Lrufiles, tmp);
-			ZERO_STRUCT(tmp);
-			SAFE_FREE(tmp);
-			lrufiles_count--;
+			DEBUG(10, ("removing first entry..."));
+			lrufiles_delete_p(tmp);
 		}
 		
+		DEBUG(10, ("adding new entry to list...\n"));
 		DLIST_ADD_END(Lrufiles, new, tmp);
 		LrufilesEnd = new;
 		lrufiles_count++;
@@ -186,6 +205,7 @@
 	}
 	Lrufiles = NULL;
 	LrufilesEnd = NULL;
+	lrufiles_count = 0;
 	DEBUG(10, ("lrufiles destroyed\n"));
 }
 
@@ -208,15 +228,8 @@
 
 	DEBUG(10, ("file entry '%s' should be deleted\n", fname));
 	found = lrufiles_search(fname);
-	if ( found != NULL ) {
-		/* should the last entry be deleted? If yes, set LrufilesEnd pointer */
-		if ( LrufilesEnd == found )
-			LrufilesEnd = found->prev;
-
-		ZERO_STRUCTP(found);
-		SAFE_FREE(found);
-		DEBUG(10, ("entry '%s' deleted\n", fname));
-	}
+	if ( found != NULL ) 
+		lrufiles_delete_p(found);
 }
 			
 
@@ -257,27 +270,14 @@
 			/* uhm, someone has changed the clock?!? */
 			/* delete entry and advise to scan file */
 			DEBUG(10, ("Clock has changed. Invalidate '%s'\n", found->fname));
-			/* set LrufilesEnd accordingly when the last entry will be deleted */
-			if ( LrufilesEnd == found )
-				LrufilesEnd = found->prev;
-
-			DLIST_REMOVE(Lrufiles, found);
-                        ZERO_STRUCT(found);
-                        SAFE_FREE(found);
+			lrufiles_delete_p(found);
 			/* file must be scanned */
 			return 1;
 		} else if ( time(NULL) >= (found->time_added + lrufiles_invalidate_time) ) {
 			/* lifetime expired */
 			/* remove entry, advide to scan */
                         DEBUG(10, ("Lifetime expired. Invalidate '%s'\n", found->fname));
-
-			/* set LrufilesEnd accordingly when the last entry will be deleted */
-			if ( LrufilesEnd == found ) 
-				LrufilesEnd = found->prev;
-
-                        DLIST_REMOVE(Lrufiles, found);
-                        ZERO_STRUCT(found);
-                        SAFE_FREE(found);
+			lrufiles_delete_p(found);
 			/* file must be scanned */
 			return 1;
 		} else {




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.