commit 7613a4a13550d212ac60de7642234b1fc495baeb
parent 68d078766e1d4981c9e566ee73459d91cd9b47ad
Author: Joris Vink <joris@coders.se>
Date: Tue, 11 Aug 2020 15:24:59 +0200
Python: Improve the kore.socket interface.
- Make sure PyBuffer_Release() is called for y* arguments.
- Make sure buffer is cleaned up for SENDTO socket ops as well.
Diffstat:
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/python.c b/src/python.c
@@ -2804,11 +2804,15 @@ static PyObject *
pysocket_send(struct pysocket *sock, PyObject *args)
{
Py_buffer buf;
+ PyObject *ret;
if (!PyArg_ParseTuple(args, "y*", &buf))
return (NULL);
- return (pysocket_op_create(sock, PYSOCKET_TYPE_SEND, buf.buf, buf.len));
+ ret = pysocket_op_create(sock, PYSOCKET_TYPE_SEND, buf.buf, buf.len);
+ PyBuffer_Release(&buf);
+
+ return (ret);
}
static PyObject *
@@ -2839,6 +2843,7 @@ pysocket_sendto(struct pysocket *sock, PyObject *args)
}
ret = pysocket_op_create(sock, PYSOCKET_TYPE_SENDTO, buf.buf, buf.len);
+ PyBuffer_Release(&buf);
op = (struct pysocket_op *)ret;
@@ -2990,7 +2995,8 @@ pysocket_op_dealloc(struct pysocket_op *op)
{
if (op->type == PYSOCKET_TYPE_RECV ||
op->type == PYSOCKET_TYPE_RECVFROM ||
- op->type == PYSOCKET_TYPE_SEND)
+ op->type == PYSOCKET_TYPE_SEND ||
+ op->type == PYSOCKET_TYPE_SENDTO)
kore_buf_cleanup(&op->buffer);
switch (op->type) {
@@ -3941,6 +3947,8 @@ pyproc_send(struct pyproc *proc, PyObject *args)
ret = pysocket_op_create(proc->in,
PYSOCKET_TYPE_SEND, buf.buf, buf.len);
+ PyBuffer_Release(&buf);
+
return (ret);
}