Fix invalid heap exception in angle

Running angle deqp test case, an invalid heap exception is thrown in
angle on both linux and windows platforms.
If build a nonsequential heap, and then erase any node of the heap,
the heap is no longer valid. If using std::push_heap or std::pop_heap
method next, this exception will be thrown out. So we should use
std::make_heap after modifying the heap.

TEST=angle_deqp_gles2_tests
TEST=angle_deqp_gles3_tests
TEST=HandleAllocatorTest.ReserveAfterReleaseBug

BUG=angleproject:2326

Change-Id: I123fc81b3365c93081d0042c69b4e5114956fe0d
Reviewed-on: https://chromium-review.googlesource.com/892961
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/HandleAllocator.cpp b/src/libANGLE/HandleAllocator.cpp
index c0c0fa2..3f7443b 100644
--- a/src/libANGLE/HandleAllocator.cpp
+++ b/src/libANGLE/HandleAllocator.cpp
@@ -114,6 +114,7 @@
         if (releasedIt != mReleasedList.end())
         {
             mReleasedList.erase(releasedIt);
+            std::make_heap(mReleasedList.begin(), mReleasedList.end(), std::greater<GLuint>());
             return;
         }
     }
diff --git a/src/libANGLE/HandleAllocator_unittest.cpp b/src/libANGLE/HandleAllocator_unittest.cpp
index 8597c15..f6efa06 100644
--- a/src/libANGLE/HandleAllocator_unittest.cpp
+++ b/src/libANGLE/HandleAllocator_unittest.cpp
@@ -170,4 +170,27 @@
     }
 }
 
+// This test reproduces invalid heap bug when reserve resources after release.
+TEST(HandleAllocatorTest, ReserveAfterReleaseBug)
+{
+    gl::HandleAllocator allocator;
+
+    for (int iteration = 1; iteration <= 16; ++iteration)
+    {
+        allocator.allocate();
+    }
+
+    allocator.release(15);
+    allocator.release(16);
+
+    for (int iteration = 1; iteration <= 14; ++iteration)
+    {
+        allocator.release(iteration);
+    }
+
+    allocator.reserve(1);
+
+    allocator.allocate();
+}
+
 }  // anonymous namespace