--- p11-kit-0.20.3/common/compat.c.orig	2014-07-04 14:48:45.000000000 +0100
+++ p11-kit-0.20.3/common/compat.c	2014-08-28 15:33:25.872571900 +0100
@@ -325,19 +325,27 @@
 
 	map->file  = CreateFile (path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL);
 	if (map->file == INVALID_HANDLE_VALUE) {
+		p11_message ("map->file (%s) == INVALID_HANDLE_VALUE", path);
 		errn = GetLastError ();
 		free (map);
 		SetLastError (errn);
 		if (errn == ERROR_PATH_NOT_FOUND || errn == ERROR_FILE_NOT_FOUND)
+		{
+			p11_message ("errn == ERROR_PATH_NOT_FOUND || errn == ERROR_FILE_NOT_FOUND, errn = %d", errn);
 			errno = ENOENT;
+		}
 		else if (errn == ERROR_ACCESS_DENIED)
+		{
+			p11_message ("errn == ERROR_ACCESS_DENIED");
 			errno = EPERM;
+		}
 		return NULL;
 	}
 
 	if (sb == NULL) {
 		if (!GetFileSizeEx (map->file, &large)) {
 			errn = GetLastError ();
+			p11_message ("GetFileSizeEx (map->file, &large), errn = %d", errn);
 			CloseHandle (map->file);
 			free (map);
 			SetLastError (errn);
@@ -352,6 +360,7 @@
 	mapping = CreateFileMapping (map->file, NULL, PAGE_READONLY, 0, 0, NULL);
 	if (!mapping) {
 		errn = GetLastError ();
+		p11_message ("CreateFileMapping (map->file, NULL, PAGE_READONLY, 0, 0, NULL), errn = %d", errn);
 		CloseHandle (map->file);
 		free (map);
 		SetLastError (errn);
@@ -365,6 +374,7 @@
 
 	if (map->data == NULL) {
 		errn = GetLastError ();
+		p11_message ("MapViewOfFile (mapping, FILE_MAP_READ, 0, 0, large.QuadPart) map->data = NULL, errn = %d", errn);
 		CloseHandle (map->file);
 		free (map);
 		SetLastError (errn);
@@ -381,8 +391,15 @@
 void
 p11_mmap_close (p11_mmap *map)
 {
-	UnmapViewOfFile (map->data);
-	CloseHandle (map->file);
+	p11_message ("p11_mmap_close (p11_mmap *map = %p) called", map);
+	if (!UnmapViewOfFile (map->data))
+	{
+		p11_message ("UnmapViewOfFile (map->data = %p) failed", map->data);
+	}
+	if (!CloseHandle (map->file))
+	{
+		p11_message ("CloseHandle (map->file = %d) failed", map->file);
+	}
 	free (map);
 }
 
