diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-01-30 18:06:44 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-01-30 18:06:44 (GMT) |
commit | 91445fbeb05f77551a8f83c5188362093916b0e1 (patch) | |
tree | 5b22bd2a0f88fe70a9833800de32b87ae9b93cc4 | |
parent | 63a615cfa1db02f18de5827ca1d2d1d3a0c58411 (diff) | |
download | cpython-91445fbeb05f77551a8f83c5188362093916b0e1.zip cpython-91445fbeb05f77551a8f83c5188362093916b0e1.tar.gz cpython-91445fbeb05f77551a8f83c5188362093916b0e1.tar.bz2 |
overlapped.c: Fix usage of the union
* read_buffer can only be used for TYPE_READ and TYPE_ACCEPT types
* write_buffer can only be used for TYPE_WRITE type
-rw-r--r-- | Modules/overlapped.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Modules/overlapped.c b/Modules/overlapped.c index 625c76e..6842efb 100644 --- a/Modules/overlapped.c +++ b/Modules/overlapped.c @@ -45,9 +45,9 @@ typedef struct { /* Type of operation */ DWORD type; union { - /* Buffer used for reading (optional) */ + /* Buffer used for reading: TYPE_READ and TYPE_ACCEPT */ PyObject *read_buffer; - /* Buffer used for writing (optional) */ + /* Buffer used for writing: TYPE_WRITE */ Py_buffer write_buffer; }; } OverlappedObject; @@ -568,13 +568,15 @@ Overlapped_dealloc(OverlappedObject *self) if (self->overlapped.hEvent != NULL) CloseHandle(self->overlapped.hEvent); - if (self->write_buffer.obj) - PyBuffer_Release(&self->write_buffer); - switch (self->type) { - case TYPE_READ: - case TYPE_ACCEPT: - Py_CLEAR(self->read_buffer); + case TYPE_READ: + case TYPE_ACCEPT: + Py_CLEAR(self->read_buffer); + break; + case TYPE_WRITE: + if (self->write_buffer.obj) + PyBuffer_Release(&self->write_buffer); + break; } PyObject_Del(self); SetLastError(olderr); @@ -648,7 +650,7 @@ Overlapped_getresult(OverlappedObject *self, PyObject *args) case ERROR_MORE_DATA: break; case ERROR_BROKEN_PIPE: - if (self->read_buffer != NULL) + if ((self->type == TYPE_READ || self->type == TYPE_ACCEPT) && self->read_buffer != NULL) break; /* fall through */ default: |