bpo-32710: Fix leak in Overlapped_WSASend() (GH-11469)


Fix a memory leak in asyncio in the ProactorEventLoop when ReadFile()
or WSASend() overlapped operation fail immediately: release the
internal buffer.
(cherry picked from commit a234e148394c2c7419372ab65b773d53a57f3625)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
diff --git a/Misc/NEWS.d/next/Library/2019-01-08-14-00-52.bpo-32710.Sn5Ujj.rst b/Misc/NEWS.d/next/Library/2019-01-08-14-00-52.bpo-32710.Sn5Ujj.rst
new file mode 100644
index 0000000..5c3961c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-01-08-14-00-52.bpo-32710.Sn5Ujj.rst
@@ -0,0 +1,3 @@
+Fix a memory leak in asyncio in the ProactorEventLoop when ``ReadFile()`` or
+``WSASend()`` overlapped operation fail immediately: release the internal
+buffer.
diff --git a/Modules/overlapped.c b/Modules/overlapped.c
index ae7cdda..4ef5a96 100644
--- a/Modules/overlapped.c
+++ b/Modules/overlapped.c
@@ -723,6 +723,7 @@
         case ERROR_IO_PENDING:
             Py_RETURN_NONE;
         default:
+            PyBuffer_Release(&self->user_buffer);
             self->type = TYPE_NOT_STARTED;
             return SetFromWindowsErr(err);
     }
@@ -1011,6 +1012,7 @@
         case ERROR_IO_PENDING:
             Py_RETURN_NONE;
         default:
+            PyBuffer_Release(&self->user_buffer);
             self->type = TYPE_NOT_STARTED;
             return SetFromWindowsErr(err);
     }