[dovecot-cvs] dovecot/src/lib-index mail-cache-fields.c,1.20,1.21

cras at dovecot.org cras at dovecot.org
Fri Mar 31 17:06:54 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv30907

Modified Files:
	mail-cache-fields.c 
Log Message:
Don't crash with "can't allocate 0 bytes of memory" if there are zero
fields in cache file.



Index: mail-cache-fields.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-fields.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- mail-cache-fields.c	14 Feb 2006 18:59:17 -0000	1.20
+++ mail-cache-fields.c	31 Mar 2006 14:06:52 -0000	1.21
@@ -198,10 +198,16 @@
 	}
 	field_hdr = CONST_PTR_OFFSET(cache->data, offset);
 
-	cache->file_field_map =
-		i_realloc(cache->file_field_map,
-			  cache->file_fields_count * sizeof(unsigned int),
-			  field_hdr->fields_count * sizeof(unsigned int));
+	if (field_hdr->fields_count != 0) {
+		cache->file_field_map =
+			i_realloc(cache->file_field_map,
+				  cache->file_fields_count *
+				  sizeof(unsigned int),
+				  field_hdr->fields_count *
+				  sizeof(unsigned int));
+	} else {
+		i_free_and_null(cache->file_field_map);
+	}
 	cache->file_fields_count = field_hdr->fields_count;
 
 	last_used = CONST_PTR_OFFSET(field_hdr, MAIL_CACHE_FIELD_LAST_USED());



More information about the dovecot-cvs mailing list