--- crypto\rand\rand_win.c	2010-03-23 02:44:35.000000000 +0400
+++ crypto\rand\rand_win.c	2013-07-08 18:58:07.510420700 +0400
@@ -356,7 +356,7 @@
 			{
 			if (gen(hProvider, sizeof(buf), buf) != 0)
 				{
-				RAND_add(buf, sizeof(buf), 0);
+				RAND_add(buf, sizeof(buf), sizeof(buf));
 				good = 1;
 #if 0
 				printf("randomness from PROV_RSA_FULL\n");
@@ -445,7 +445,7 @@
 	 * interactive seeding is encouraged.)
 	 */
 
-	if (kernel)
+	if (kernel && !good)
 		{
 		CREATETOOLHELP32SNAPSHOT snap;
 		CLOSETOOLHELP32SNAPSHOT close_snap;
@@ -608,8 +608,10 @@
 
 			}
 
-		FreeLibrary(kernel);
 		}
+
+		if (kernel)
+			FreeLibrary(kernel);
 	}
 #endif /* !OPENSSL_SYS_WINCE */
 
