[dovecot-cvs] dovecot/src/lib file-cache.c,1.12.2.5,1.12.2.6

tss at dovecot.org tss at dovecot.org
Sun Dec 3 15:22:00 UTC 2006


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

Modified Files:
      Tag: branch_1_0
	file-cache.c 
Log Message:
If mremap_anon() fails, don't leak/crash.



Index: file-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/file-cache.c,v
retrieving revision 1.12.2.5
retrieving revision 1.12.2.6
diff -u -d -r1.12.2.5 -r1.12.2.6
--- file-cache.c	3 Dec 2006 15:09:35 -0000	1.12.2.5
+++ file-cache.c	3 Dec 2006 15:21:27 -0000	1.12.2.6
@@ -50,6 +50,7 @@
 {
 	size_t page_size = mmap_get_page_size();
 	uoff_t diff = size % page_size;
+	void *new_base;
 
 	if (diff != 0)
 		size += page_size - diff;
@@ -73,14 +74,14 @@
 			return -1;
 		}
 	} else {
-		cache->mmap_base = mremap_anon(cache->mmap_base,
-					       cache->mmap_length,
-					       size, MREMAP_MAYMOVE);
-		if (cache->mmap_base == MAP_FAILED) {
+		new_base = mremap_anon(cache->mmap_base, cache->mmap_length,
+				       size, MREMAP_MAYMOVE);
+		if (new_base == MAP_FAILED) {
 			i_error("mremap_anon(%"PRIuUOFF_T") failed: %m", size);
-			cache->mmap_length = 0;
 			return -1;
 		}
+
+		cache->mmap_base = new_base;
 	}
 	cache->mmap_length = size;
 	return 0;



More information about the dovecot-cvs mailing list