Browse code

Better reclaiming when running short of memory

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1180 77e5149b-7576-45b1-b177-96237e5ba77b

Nigel Horne authored on 2004/12/14 19:31:08
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Dec 14 10:30:15 GMT 2004 (njh)
2
+----------------------------------
3
+  * libclamav/message.c:	better recovery if memory softlimit is hit
4
+
1 5
 Mon Dec 13 11:21:28 GMT 2004 (njh)
2 6
 ----------------------------------
3 7
   * clamav-milter:	INSTALL: Added notes about FreeBSD5
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: message.c,v $
20
+ * Revision 1.130  2004/12/14 10:27:57  nigelhorne
21
+ * Better reclaiming when running short of memory
22
+ *
20 23
  * Revision 1.129  2004/12/10 15:20:23  nigelhorne
21 24
  * Handle empty content-type fields
22 25
  *
... ...
@@ -384,7 +387,7 @@
384 384
  * uuencodebegin() no longer static
385 385
  *
386 386
  */
387
-static	char	const	rcsid[] = "$Id: message.c,v 1.129 2004/12/10 15:20:23 nigelhorne Exp $";
387
+static	char	const	rcsid[] = "$Id: message.c,v 1.130 2004/12/14 10:27:57 nigelhorne Exp $";
388 388
 
389 389
 #if HAVE_CONFIG_H
390 390
 #include "clamav-config.h"
... ...
@@ -1975,7 +1978,7 @@ messageToText(message *m)
1975 1975
 			 */
1976 1976
 			if((data[0] == '\n') || (data[0] == '\0'))
1977 1977
 				last->t_line = NULL;
1978
-			else if(line && (strncmp(data, line, strlen(line)) == 0)) {
1978
+			else if(line && (strncmp((const char *)data, line, strlen(line)) == 0)) {
1979 1979
 #ifdef	CL_DEBUG
1980 1980
 				cli_dbgmsg("messageToText: decoded line is the same(%s)\n", data);
1981 1981
 #endif
... ...
@@ -2606,6 +2609,8 @@ messageDedup(message *m)
2606 2606
 	const text *t1;
2607 2607
 	size_t saved = 0;
2608 2608
 
2609
+	cli_dbgmsg("messageDedup\n");
2610
+
2609 2611
 	t1 = m->dedupedThisFar ? m->dedupedThisFar : m->body_first;
2610 2612
 
2611 2613
 	for(t1 = m->body_first; t1; t1 = t1->t_next) {
... ...
@@ -2622,6 +2627,7 @@ messageDedup(message *m)
2622 2622
 		d1 = lineGetData(l1);
2623 2623
 		if(strlen(d1) < 8)
2624 2624
 			continue;	/* wouldn't recover many bytes */
2625
+
2625 2626
 		r1 = (unsigned int)lineGetRefCount(l1);
2626 2627
 		if(r1 == 255)
2627 2628
 			continue;
... ...
@@ -2645,23 +2651,25 @@ messageDedup(message *m)
2645 2645
 
2646 2646
 			if(l2 == NULL)
2647 2647
 				continue;
2648
-			if((r1 + (unsigned int)lineGetRefCount(l2)) > 255)
2649
-				continue;
2650 2648
 			d2 = lineGetData(l2);
2651 2649
 			if(d1 == d2)
2652 2650
 				/* already linked */
2653 2651
 				continue;
2654 2652
 			if(strcmp(d1, d2) == 0) {
2655 2653
 				if(lineUnlink(l2) == NULL)
2656
-					saved += strlen(d1);
2654
+					saved += strlen(d1) + 1;
2657 2655
 				t2->t_line = lineLink(l1);
2658 2656
 				if(t2->t_line == NULL) {
2659 2657
 					cli_errmsg("messageDedup: out of memory\n");
2660 2658
 					return;
2661 2659
 				}
2660
+				if(++r1 == 255)
2661
+					break;
2662 2662
 			}
2663 2663
 		}
2664 2664
 	}
2665
+
2666
+	cli_dbgmsg("messageDedup reclaimed %u bytes\n", saved);
2665 2667
 	m->dedupedThisFar = t1;
2666 2668
 }
2667 2669