@@ -4072,11 +4072,13 @@ sock_sendmsg(PySocketSockObject *s, PyObject *args)
40724072 if (ncmsgbufs > 0 ) {
40734073 struct cmsghdr * cmsgh = NULL ;
40744074
4075- if (( msg . msg_control = controlbuf =
4076- PyMem_Malloc ( controllen )) == NULL ) {
4075+ controlbuf = PyMem_Malloc ( controllen );
4076+ if ( controlbuf == NULL ) {
40774077 PyErr_NoMemory ();
40784078 goto finally ;
40794079 }
4080+ msg .msg_control = controlbuf ;
4081+
40804082 msg .msg_controllen = controllen ;
40814083
40824084 /* Need to zero out the buffer as a workaround for glibc's
@@ -4141,8 +4143,10 @@ sock_sendmsg(PySocketSockObject *s, PyObject *args)
41414143 PyBuffer_Release (& cmsgs [i ].data );
41424144 PyMem_Free (cmsgs );
41434145 Py_XDECREF (cmsg_fast );
4144- for (i = 0 ; i < ndatabufs ; i ++ )
4146+ PyMem_Free (msg .msg_iov );
4147+ for (i = 0 ; i < ndatabufs ; i ++ ) {
41454148 PyBuffer_Release (& databufs [i ]);
4149+ }
41464150 PyMem_Free (databufs );
41474151 return retval ;
41484152}
@@ -4243,7 +4247,8 @@ sock_sendmsg_afalg(PySocketSockObject *self, PyObject *args, PyObject *kwds)
42434247
42444248 controlbuf = PyMem_Malloc (controllen );
42454249 if (controlbuf == NULL ) {
4246- return PyErr_NoMemory ();
4250+ PyErr_NoMemory ();
4251+ goto finally ;
42474252 }
42484253 memset (controlbuf , 0 , controllen );
42494254
@@ -4315,8 +4320,10 @@ sock_sendmsg_afalg(PySocketSockObject *self, PyObject *args, PyObject *kwds)
43154320 if (iv .buf != NULL ) {
43164321 PyBuffer_Release (& iv );
43174322 }
4318- for (i = 0 ; i < ndatabufs ; i ++ )
4323+ PyMem_Free (msg .msg_iov );
4324+ for (i = 0 ; i < ndatabufs ; i ++ ) {
43194325 PyBuffer_Release (& databufs [i ]);
4326+ }
43204327 PyMem_Free (databufs );
43214328 return retval ;
43224329}
0 commit comments