diff --git a/tests/test_document.cpp b/tests/test_document.cpp
index d81458ab911a173528feb6598517a55523cedd01..1545e19b892f09486e423c6da2abf0756141458d 100644
--- a/tests/test_document.cpp
+++ b/tests/test_document.cpp
@@ -302,11 +302,33 @@ TEST(document_load_file_error)
 	pugi::xml_document doc;
 
 	CHECK(doc.load_file("filedoesnotexist").status == status_file_not_found);
+}
 
+TEST(document_load_file_out_of_memory)
+{
 	test_runner::_memory_fail_threshold = 1;
+
+	pugi::xml_document doc;
 	CHECK_ALLOC_FAIL(CHECK(doc.load_file("tests/data/small.xml").status == status_out_of_memory));
 }
 
+TEST(document_load_file_out_of_memory_file_leak)
+{
+	test_runner::_memory_fail_threshold = 1;
+
+	pugi::xml_document doc;
+
+	for (int i = 0; i < 256; ++i)
+	{
+		CHECK_ALLOC_FAIL(CHECK(doc.load_file("tests/data/small.xml").status == status_out_of_memory));
+	}
+
+	test_runner::_memory_fail_threshold = 0;
+
+	CHECK(doc.load_file("tests/data/small.xml"));
+	CHECK_NODE(doc, STR("<node />"));
+}
+
 TEST(document_load_file_error_previous)
 {
 	pugi::xml_document doc;