diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/clamscan/manager.c clamav-devel.jm-pl4b.allocfixes/clamscan/manager.c
--- clamav-devel.jm-pl4b/clamscan/manager.c	Sun May 16 20:21:56 2004
+++ clamav-devel.jm-pl4b.allocfixes/clamscan/manager.c	Sun May 16 17:32:29 2004
@@ -164,12 +164,16 @@
     /* set (default) limits */
 
     limits = (struct cl_limits *) calloc(1, sizeof(struct cl_limits));
+    if(!limits)
+	exit(60);
 
     if(optl(opt, "max-space")) {
 	char *cpy, *ptr;
 	ptr = getargl(opt, "max-space");
 	if(tolower(ptr[strlen(ptr) - 1]) == 'm') {
 	    cpy = mcalloc(strlen(ptr), sizeof(char));
+	    if(!cpy)
+		exit(60);
 	    strncpy(cpy, ptr, strlen(ptr) - 1);
 	    limits->maxfilesize = atoi(cpy) * 1024 * 1024;
 	    free(cpy);
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/blob.c clamav-devel.jm-pl4b.allocfixes/libclamav/blob.c
--- clamav-devel.jm-pl4b/libclamav/blob.c	Sun May 16 20:21:28 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/blob.c	Sun May 16 17:32:29 2004
@@ -166,8 +166,12 @@
 		b->size = len * 4;
 		b->data = cli_malloc(b->size);
 	} else if(b->size < b->len + len) {
+		void * p = NULL;
 		b->size += len * 4;
-		b->data = cli_realloc(b->data, b->size);
+		p = cli_realloc(b->data, b->size);
+		if(!p)
+		    return;
+		b->data = p;
 	}
 
 	if(b->data) {
@@ -200,8 +204,13 @@
 	b->isClosed = 1;
 
 	if(b->size != b->len) {
+		void * p = NULL;
+		
 		b->size = b->len;
-		b->data = cli_realloc(b->data, b->size);
+		p = cli_realloc(b->data, b->size);
+		if(!p)
+		    return;
+		b->data = p;
 	}
 }
 
@@ -252,7 +261,11 @@
 		b->size = len;
 		b->data = cli_malloc(len);
 	} else {
+		void * p = NULL;
 		b->size += len;
-		b->data = cli_realloc(b->data, b->size);
+		p = cli_realloc(b->data, b->size);
+		if(!p)
+		    return;
+		b->data = p;
 	}
 }
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/cvd.c clamav-devel.jm-pl4b.allocfixes/libclamav/cvd.c
--- clamav-devel.jm-pl4b/libclamav/cvd.c	Sun May 16 20:21:28 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/cvd.c	Sun May 16 17:32:29 2004
@@ -55,6 +55,8 @@
 
 
     fullname = (char *) calloc(sizeof(char), strlen(destdir) + 100 + 5);
+    if(!fullname)
+	return -1;
 
     while(1) {
 
@@ -163,6 +165,8 @@
     }
 
     cvd = (struct cl_cvd *) cli_calloc(1, sizeof(struct cl_cvd));
+    if(!cvd)
+	return NULL;
 
     if(!(cvd->time = cli_strtok(head, 1, ":"))) {
 	cli_errmsg("CVD -> Can't extract time from header.\n");
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/dsig.c clamav-devel.jm-pl4b.allocfixes/libclamav/dsig.c
--- clamav-devel.jm-pl4b/libclamav/dsig.c	Sun May 16 20:21:28 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/dsig.c	Sun May 16 17:32:29 2004
@@ -83,6 +83,8 @@
 
     mpz_init(p);
     decoded = (char *) calloc(plainlen + 1, sizeof(char));
+    if(!decoded)
+	return NULL;
 
     mpz_powm(p, c, e, n); /* plain = cipher^e mod n */
     mpz_clear(c);
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/mbox.c clamav-devel.jm-pl4b.allocfixes/libclamav/mbox.c
--- clamav-devel.jm-pl4b/libclamav/mbox.c	Sun May 16 20:21:28 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/mbox.c	Tue May 18 07:01:34 2004
@@ -387,7 +389,10 @@
 		return 0;
 	}
 	m = messageCreate();
-	assert(m != NULL);
+	if(!m) {
+		assert(m);
+		return -1;
+	}
 
 	if(initialiseTables(&rfc821Table, &subtypeTable) < 0) {
 		messageDestroy(m);
@@ -669,8 +674,11 @@
 			aText = textAddMessage(aText, mainMessage);
 			break;
 		case TEXT:
-			if(tableFind(subtypeTable, mimeSubtype) == PLAIN)
+			if(tableFind(subtypeTable, mimeSubtype) == PLAIN) {
 				aText = textCopy(messageGetBody(mainMessage));
+				if(!aText)
+					 return 0;
+			}
 			break;
 		case MULTIPART:
 
@@ -736,6 +744,11 @@
 				int lines = 0;
 
 				aMessage = messages[multiparts] = messageCreate();
+				if(!aMessage) {
+					assert(aMessage);
+					continue;
+				}
+
 
 				cli_dbgmsg("Now read in part %d\n", multiparts);
 
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/message.c clamav-devel.jm-pl4b.allocfixes/libclamav/message.c
--- clamav-devel.jm-pl4b/libclamav/message.c	Sun May 16 20:21:28 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/message.c	Tue May 18 07:02:35 2004
@@ -169,7 +169,7 @@
 #endif
 
 #ifndef	CL_DEBUG
-/*#define	NDEBUG	/* map CLAMAV debug onto standard */
+/*#define	NDEBUG*/	/* map CLAMAV debug onto standard */
 #endif
 
 #ifdef CL_THREAD_SAFE
@@ -250,6 +250,8 @@
 messageCreate(void)
 {
 	message *m = (message *)cli_calloc(1, sizeof(message));
+	if(!m)
+	   return NULL;
 
 	m->mimeType = NOMIME;
 	m->encodingType = NOENCODING;
@@ -443,8 +445,13 @@
 			return;	/* already in there */
 
 	if(offset == m->numberOfArguments) {
+		char ** p = NULL;
+
 		m->numberOfArguments++;
-		m->mimeArguments = (char **)cli_realloc(m->mimeArguments, m->numberOfArguments * sizeof(char *));
+		p = cli_realloc(m->mimeArguments, m->numberOfArguments * sizeof(char *));
+		if(!p)
+		    return;
+		m->mimeArguments = p;
 	}
 
 	m->mimeArguments[offset] = strdup(arg);
@@ -572,6 +579,8 @@
 			*ptr = '\0';
 
 			field = cli_malloc(strlen(key) + strlen(data) + 2);
+			if(!field)
+			    return;
 			sprintf(field, "%s=%s", key, data);
 
 			free((char *)key);
@@ -593,6 +602,8 @@
 
 			len = (size_t)string - (size_t)key + 1;
 			field = cli_malloc(len);
+			if(!field)
+			    return;
 
 			memcpy(field, key, len - 1);
 			field[len - 1] = '\0';
@@ -704,6 +715,7 @@
  * If needed a copy of the given line is taken which the caller must free
  * Line must not be terminated by a \n
  */
+
 int
 messageAddLine(message *m, const char *line, int takeCopy)
 {
@@ -732,6 +744,12 @@
 		assert(m->body_last->t_text != NULL);
 	} else {
 		assert(line != NULL);
+#ifdef CL_DEBUG
+		{
+			char * p = strdup(line);
+			free(p);
+		}
+#endif
 		m->body_last->t_text = (char *)line;
 	}
 
@@ -900,6 +918,12 @@
 		 *
 		 * See RFC1741
 		 */
+		
+		if(!tmp) {
+		   blobDestroy(b);
+		   return NULL;
+		}
+
 		while((t_line = t_line->t_next) != NULL)
 			blobAddData(tmp, (unsigned char *)t_line->t_text, strlen(t_line->t_text));
 
@@ -934,6 +958,11 @@
 		cli_dbgmsg("decode HQX7 message (%lu bytes)\n", len);
 
 		ptr = cli_malloc(len);
+		if(!ptr) {
+		    blobDestroy(tmp);
+		    blobDestroy(b);
+		    return NULL;
+		}
 		memcpy(ptr, data, len);
 		bytenumber = 0;
 
@@ -998,6 +1027,11 @@
 		 */
 		if(memchr(data, 0x90, newlen)) {
 			blob *u = blobCreate();	/* uncompressed data */
+			if(!u) {
+			    blobDestroy(tmp);
+			    blobDestroy(b);
+			    return NULL;
+			}
 
 			/*
 			 * Includes compression
@@ -1053,10 +1087,20 @@
 		 */
 		byte = data[0];
 		filename = cli_malloc(byte + 1);
+		if(!filename) {
+		   blobDestroy(tmp);
+		   blobDestroy(b);
+		   return NULL;
+		}
 		memcpy(filename, &data[1], byte);
 		filename[byte] = '\0';
 		blobSetFilename(b, filename);
 		ptr = cli_malloc(strlen(filename) + 6);
+		if(!ptr) {
+		   blobDestroy(tmp);
+		   blobDestroy(b);
+		   return NULL;
+		}
 		sprintf(ptr, "name=%s", filename);
 		messageAddArgument(m, ptr);
 		free(ptr);
@@ -1166,7 +1210,7 @@
 messageToText(const message *m)
 {
 	text *first = NULL, *last = NULL;
-	const text *t_line;
+	const text *t_line = NULL;
 
 	assert(m != NULL);
 
@@ -1175,15 +1219,20 @@
 		 * Fast copy
 		 */
 		for(t_line = messageGetBody(m); t_line; t_line = t_line->t_next) {
-			if(first == NULL)
+			if(first == NULL) {
 				first = last = cli_malloc(sizeof(text));
-			else {
+				if(!first)
+					return NULL;
+			} else {
 				last->t_next = cli_malloc(sizeof(text));
+				if(!last->t_next) {
+					textDestroy(first);
+					return NULL;
+				}
 				last = last->t_next;
 			}
 
-			if((last == NULL) ||
-			   ((last->t_text = strdup(t_line->t_text)) == NULL)) {
+			if(!(last->t_text = strdup(t_line->t_text))) {
 				textDestroy(first);
 				return NULL;
 			}
@@ -1219,15 +1268,25 @@
 
 			assert(uptr <= &data[sizeof(data)]);
 
-			if(first == NULL)
+			if(first == NULL) {
 				first = last = cli_malloc(sizeof(text));
-			else {
+				if(!first )
+					return NULL;
+			} else {
 				last->t_next = cli_malloc(sizeof(text));
+				if(!last->t_next) {
+					textDestroy(first);
+					return NULL;
+				}
 				last = last->t_next;
 			}
 
 			last->t_text = strdup((char *)data);
-			assert(last->t_text != NULL);
+			if(!last->t_text) {
+				assert(last->t_text != NULL);
+				textDestroy(first);
+				return NULL;
+			}
 
 			if(messageGetEncoding(m) == BASE64)
 				if(strchr(line, '='))
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/ole2_extract.c clamav-devel.jm-pl4b.allocfixes/libclamav/ole2_extract.c
--- clamav-devel.jm-pl4b/libclamav/ole2_extract.c	Sun May 16 20:21:28 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/ole2_extract.c	Sun May 16 17:32:29 2004
@@ -536,7 +536,7 @@
 {
 	unsigned char buff[(1 << hdr->log2_big_block_size)];
 	int32_t current_block, ofd, len, offset;
-	char *name, *newname;
+	char *name = NULL, *newname = NULL;
 
 	if (prop->type != 2) {
 		/* Not a file */
@@ -561,6 +561,11 @@
 	}
 
 	newname = (char *) cli_malloc(strlen(name) + strlen(dir) + 2);
+	if(!newname) {
+	    if(name)
+	       free(name);
+	    return FALSE;
+	}
 	sprintf(newname, "%s/%s", dir, name);
 	free(name);
 
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/others.c clamav-devel.jm-pl4b.allocfixes/libclamav/others.c
--- clamav-devel.jm-pl4b/libclamav/others.c	Sun May 16 20:21:28 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/others.c	Sun May 16 17:32:29 2004
@@ -174,6 +174,8 @@
     fclose(fd);
 
     md5str = (char*) calloc(32 + 1, sizeof(char));
+    if(!md5str)
+	return NULL;
 
     for(i=0; i<16; i++)
 	cnt += sprintf(md5str + cnt, "%02x", buffer[i]);
@@ -190,6 +192,8 @@
     md5_stream(fd, &buffer);
 
     md5str = (char*) calloc(32 + 1, sizeof(char));
+    if(!md5str)
+	return NULL;
 
     for(i=0; i<16; i++)
 	cnt += sprintf(md5str + cnt, "%02x", buffer[i]);
@@ -211,6 +215,8 @@
     memcpy(oldmd5buff, md5buff, 16);
 
     md5str = (char*) cli_calloc(32 + 1, sizeof(char));
+    if(!md5str)
+	return NULL;
 
     for(i=0; i<16; i++)
 	cnt += sprintf(md5str + cnt, "%02x", md5buff[i]);
@@ -350,6 +356,8 @@
 		if(dent->d_ino) {
 		    if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
 			fname = cli_calloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char));
+			if(!fname)
+			    return 0;
 			sprintf(fname, "%s/%s", dirname, dent->d_name);
 
 			/* stat the file */
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/readdb.c clamav-devel.jm-pl4b.allocfixes/libclamav/readdb.c
--- clamav-devel.jm-pl4b/libclamav/readdb.c	Sun May 16 20:21:28 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/readdb.c	Sun May 16 17:32:29 2004
@@ -295,9 +295,16 @@
 	if(dent->d_ino) {
 	    if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..") && (cli_strbcasestr(dent->d_name, ".db") || cli_strbcasestr(dent->d_name, ".db2") || cli_strbcasestr(dent->d_name, ".cvd"))) {
 
+		void * p = NULL;
+		
 		dbstat->no++;
-		dbstat->stattab = (struct stat *) realloc(dbstat->stattab, dbstat->no * sizeof(struct stat));
+		p = (struct stat *) realloc(dbstat->stattab, dbstat->no * sizeof(struct stat));
+		if(!p)	
+		    return CL_EMEM;
+		dbstat->stattab = p;
                 fname = cli_calloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char));
+		if(!fname)
+		    return CL_EMEM;
 		sprintf(fname, "%s/%s", dirname, dent->d_name);
 		stat(fname, &dbstat->stattab[dbstat->no - 1]);
 		free(fname);
@@ -335,6 +342,8 @@
 	    if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..") && (cli_strbcasestr(dent->d_name, ".db") || cli_strbcasestr(dent->d_name, ".db2") || cli_strbcasestr(dent->d_name, ".cvd"))) {
 
                 fname = cli_calloc(strlen(dbstat->dir) + strlen(dent->d_name) + 2, sizeof(char));
+		if(!fname)
+		    return CL_EMEM;
 		sprintf(fname, "%s/%s", dbstat->dir, dent->d_name);
 		stat(fname, &sb);
 		free(fname);
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/scanners.c clamav-devel.jm-pl4b.allocfixes/libclamav/scanners.c
--- clamav-devel.jm-pl4b/libclamav/scanners.c	Sun May 16 20:21:56 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/scanners.c	Sun May 16 17:32:29 2004
@@ -722,6 +722,10 @@
 		if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
 		    /* build the full name */
 		    fname = cli_calloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char));
+		    if(!fname) {
+			closedir(dd);    
+			return(CL_EMEM);
+		    }
 		    sprintf(fname, "%s/%s", dirname, dent->d_name);
 
 		    /* stat the file */
@@ -769,6 +773,10 @@
 
 	for(i = 0; i < vba_project->count; i++) {
 	    fullname = (char *) cli_malloc(strlen(vba_project->dir) + strlen(vba_project->name[i]) + 2);
+	    if(!fullname) {
+		ret = CL_EMEM;
+		break;
+	    }
 	    sprintf(fullname, "%s/%s", vba_project->dir, vba_project->name[i]);
 	    fd = open(fullname, O_RDONLY);
 	    if(fd == -1) {
@@ -804,6 +812,10 @@
     } else if ((vba_project = (vba_project_t *) wm_dir_read(dirname))) {
     	for (i = 0; i < vba_project->count; i++) {
 		fullname = (char *) cli_malloc(strlen(vba_project->dir) + strlen(vba_project->name[i]) + 2);
+		if(!fullname) {
+		    ret = CL_EMEM;
+		    break;
+		}
 		sprintf(fullname, "%s/%s", vba_project->dir, vba_project->name[i]);
 		fd = open(fullname, O_RDONLY);
 		if(fd == -1) {
@@ -847,6 +859,10 @@
 		if(strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
 		    /* build the full name */
 		    fname = cli_calloc(strlen(dirname) + strlen(dent->d_name) + 2, sizeof(char));
+		    if(!fname) {
+			closedir(dd);
+			return CL_EMEM;
+		    }
 		    sprintf(fname, "%s/%s", dirname, dent->d_name);
 
 		    /* stat the file */
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/str.c clamav-devel.jm-pl4b.allocfixes/libclamav/str.c
--- clamav-devel.jm-pl4b/libclamav/str.c	Sun May 16 20:21:28 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/str.c	Sun May 16 17:32:29 2004
@@ -179,6 +179,8 @@
 	return NULL;
     }
     buffer = malloc(j-i+1);
+    if(!buffer)
+	return NULL;
     strncpy(buffer, line+i, j-i);
     buffer[j-i] = '\0';
 
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/text.c clamav-devel.jm-pl4b.allocfixes/libclamav/text.c
--- clamav-devel.jm-pl4b/libclamav/text.c	Sun May 16 20:21:28 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/text.c	Tue May 18 07:00:12 2004
@@ -138,19 +151,27 @@
 	text *first = NULL, *last = NULL;
 
 	while(t_head) {
-		if(first == NULL)
+		if(first == NULL) {
 			last = first = (text *)cli_malloc(sizeof(text));
-		else {
+			if(!last) {
+				assert(last);
+				return NULL;
+			}
+		} else {
 			last->t_next = (text *)cli_malloc(sizeof(text));
+			if(!last->t_next) {
+				assert(last->t_next);
+				textDestroy(first);
+				return NULL;
+			}
 			last = last->t_next;
 		}
-
-		assert(last != NULL);
-
 		last->t_text = strdup(t_head->t_text);
-
-		assert(last->t_text != NULL);
-
+		if(!last->t_text) {
+			assert(last->t_text);
+			textDestroy(first);
+			return NULL;
+		}
 		t_head = t_head->t_next;
 	}
 
@@ -182,10 +203,17 @@
 		t_head = t_head->t_next;
 
 		assert(t_head != NULL);
+		if(!t_head)
+			return ret;
 
 		t_head->t_text = strdup(t->t_text);
 
 		assert(t_head->t_text != NULL);
+		if(!t_head->t_text) {
+			free(t_head->t_next);
+			t_head->t_next = NULL;
+			return ret;
+		}
 
 		t = t->t_next;
 	}
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/unrarlib.c clamav-devel.jm-pl4b.allocfixes/libclamav/unrarlib.c
--- clamav-devel.jm-pl4b/libclamav/unrarlib.c	Sun May 16 20:21:28 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/unrarlib.c	Sun May 16 17:32:29 2004
@@ -553,6 +553,12 @@
     if((void*)(*(DWORD*)list) == NULL)      /* first entry                  */
     {
       tmp_List = malloc(sizeof(ArchiveList_struct));
+      if(!tmp_List) {
+	  fclose(ArcPtr);
+	  free(UnpMemory);
+	  return FALSE;
+      }
+	  
       tmp_List->next = NULL;
 
       (*(DWORD*)list) = (DWORD)tmp_List;
@@ -560,11 +566,24 @@
     } else                                  /* add entry                    */
     {
       tmp_List->next = malloc(sizeof(ArchiveList_struct));
+      if(!tmp_List) {
+	  fclose(ArcPtr);
+	  free(UnpMemory);
+	  return FALSE;
+      }
+	  
       tmp_List = (ArchiveList_struct*) tmp_List->next;
       tmp_List->next = NULL;
     }
 
     tmp_List->item.Name = malloc(NewLhd.NameSize + 1);
+    if(!tmp_List->item.Name) {
+	fclose(ArcPtr);
+	free(UnpMemory);
+	free(tmp_List);
+	return FALSE;
+    }
+	  
     strcpy(tmp_List->item.Name, ArcFileName);
     tmp_List->item.NameSize = NewLhd.NameSize;
     tmp_List->item.PackSize = NewLhd.PackSize;
diff -ur --exclude=auto* --exclude=configure* clamav-devel.jm-pl4b/libclamav/vba_extract.c clamav-devel.jm-pl4b.allocfixes/libclamav/vba_extract.c
--- clamav-devel.jm-pl4b/libclamav/vba_extract.c	Sun May 16 20:21:28 2004
+++ clamav-devel.jm-pl4b.allocfixes/libclamav/vba_extract.c	Sun May 16 17:32:29 2004
@@ -219,9 +219,10 @@
 				continue;
 			}
 			buff = (unsigned char *) cli_malloc(10);
-			if (cli_readn(fd, buff, 10) != 10) {
+			if (!buff || (cli_readn(fd, buff, 10) != 10) ) {
 				cli_errmsg("failed to read blob\n");
-				free(buff);
+				if(buff)
+				    free(buff);
 				free(name);
 				close(fd);
 				return FALSE;
@@ -269,6 +270,8 @@
 	cli_dbgmsg("in vba56_dir_read()\n");
 
 	fullname = (char *) cli_malloc(strlen(dir) + 15);
+	if(!fullname)
+	    return NULL;
 	sprintf(fullname, "%s/_VBA_PROJECT", dir);
         fd = open(fullname, O_RDONLY);
 
@@ -424,10 +427,23 @@
 	cli_dbgmsg("\nVBA Record count: %d\n", record_count);
 	
 	vba_project = (vba_project_t *) cli_malloc(sizeof(struct vba_project_tag));
+	if(!vba_project) {
+	    close(fd);
+	    return NULL;
+	}
 	vba_project->name = (char **) cli_malloc(sizeof(char *) * record_count);
+	if(vba_project->name) {
+	    free(vba_project);
+	    return NULL;
+	}
 	vba_project->dir = strdup(dir);
 	vba_project->offset = (uint32_t *) cli_malloc (sizeof(uint32_t) *
 					record_count);
+	if(vba_project->offset) {
+	    free(vba_project->name);
+	    free(vba_project);
+	    return NULL;
+	}
 	vba_project->count = record_count;
 	for (i=0 ; i < record_count ; i++) {
 		if (cli_readn(fd, &length, 2) != 2) {
@@ -524,10 +540,16 @@
 {
 	if (array->length == 0) {
 		array->data = (unsigned char *) cli_malloc(len);
+		if(!array->data)
+		    return;
 		array->length = len;
 		memcpy(array->data, src, len);
 	} else {
-		array->data = realloc(array->data, array->length+len);
+		void * p = NULL;
+		p = realloc(array->data, array->length+len);
+		if(!p)
+		    return;
+		array->data = p;
 		memcpy(array->data+array->length, src, len);
 		array->length += len;
 	}
@@ -1004,14 +1026,16 @@
 
 	offset_end += size;
 	while (lseek(fd, 0, SEEK_CUR) < offset_end) {
+		macro_extname_t * p = NULL;
+		
 		macro_extnames->count++;
-		macro_extnames->macro_extname = (macro_extname_t *)
-			cli_realloc(macro_extnames->macro_extname,
+		p = (macro_extname_t *) cli_realloc(macro_extnames->macro_extname,
 				sizeof(macro_extname_t) * macro_extnames->count);
-		if (macro_extnames->macro_extname == NULL) {
+		if (p == NULL) {
 			cli_dbgmsg("read macro_extnames failed\n");
 			goto abort;;
 		}
+		macro_extnames->macro_extname = p;
 
 		macro_extname = &macro_extnames->macro_extname[macro_extnames->count-1];
 		if (is_unicode) {
diff -urN --exclude=Makefile.in --exclude=aclocal.m4 --exclude=autom4* --exclude=*~ --exclude=configure --exclude=target.h --exclude=Makefile --exclude=*.o --exclude=.deps --exclude=clamav-config.h clamav-devel.jm-pl4b.allocfixes.0/libclamav/matcher.c clamav-devel.jm-pl5a/libclamav/matcher.c
--- clamav-devel.jm-pl4b.allocfixes.0/libclamav/matcher.c	Sun May 16 17:29:30 2004
+++ clamav-devel.jm-pl5a/libclamav/matcher.c	Tue May 18 10:57:44 2004
@@ -51,6 +51,7 @@
 	next = pos->trans[((unsigned char) pattern->pattern[i]) & 0xff]; 
 
 	if(!next) {
+	    void * p = NULL;
 	    next = (struct cl_node *) cli_calloc(1, sizeof(struct cl_node));
 	    if(!next) {
 		cli_dbgmsg("Unable to allocate pattern node (%d)\n", sizeof(struct cl_node));
@@ -58,11 +59,13 @@
 	    }
 
 	    root->nodes++;
-	    root->nodetable = (struct cl_node **) realloc(root->nodetable, (root->nodes) * sizeof(struct cl_node *));
-	    if (root->nodetable == NULL) {
+	    p = (struct cl_node **) realloc(root->nodetable, (root->nodes) * sizeof(struct cl_node *));
+	    if (p == NULL) {
 		cli_dbgmsg("Unable to realloc nodetable (%d)\n", (root->nodes) * sizeof(struct cl_node *));
+		free(next);
 		return CL_EMEM;
 	    }
+	    root->nodetable = p;
 	    root->nodetable[root->nodes - 1] = next;
 
 	    pos->trans[((unsigned char) pattern->pattern[i]) & 0xff] = next;
