Kaydet (Commit) 91445fbe authored tarafından Victor Stinner's avatar Victor Stinner

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
üst 63a615cf
...@@ -45,9 +45,9 @@ typedef struct { ...@@ -45,9 +45,9 @@ typedef struct {
/* Type of operation */ /* Type of operation */
DWORD type; DWORD type;
union { union {
/* Buffer used for reading (optional) */ /* Buffer used for reading: TYPE_READ and TYPE_ACCEPT */
PyObject *read_buffer; PyObject *read_buffer;
/* Buffer used for writing (optional) */ /* Buffer used for writing: TYPE_WRITE */
Py_buffer write_buffer; Py_buffer write_buffer;
}; };
} OverlappedObject; } OverlappedObject;
...@@ -568,13 +568,15 @@ Overlapped_dealloc(OverlappedObject *self) ...@@ -568,13 +568,15 @@ Overlapped_dealloc(OverlappedObject *self)
if (self->overlapped.hEvent != NULL) if (self->overlapped.hEvent != NULL)
CloseHandle(self->overlapped.hEvent); CloseHandle(self->overlapped.hEvent);
if (self->write_buffer.obj)
PyBuffer_Release(&self->write_buffer);
switch (self->type) { switch (self->type) {
case TYPE_READ: case TYPE_READ:
case TYPE_ACCEPT: case TYPE_ACCEPT:
Py_CLEAR(self->read_buffer); Py_CLEAR(self->read_buffer);
break;
case TYPE_WRITE:
if (self->write_buffer.obj)
PyBuffer_Release(&self->write_buffer);
break;
} }
PyObject_Del(self); PyObject_Del(self);
SetLastError(olderr); SetLastError(olderr);
...@@ -648,7 +650,7 @@ Overlapped_getresult(OverlappedObject *self, PyObject *args) ...@@ -648,7 +650,7 @@ Overlapped_getresult(OverlappedObject *self, PyObject *args)
case ERROR_MORE_DATA: case ERROR_MORE_DATA:
break; break;
case ERROR_BROKEN_PIPE: case ERROR_BROKEN_PIPE:
if (self->read_buffer != NULL) if ((self->type == TYPE_READ || self->type == TYPE_ACCEPT) && self->read_buffer != NULL)
break; break;
/* fall through */ /* fall through */
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment