[CalendarServer-changes] [11045] CalendarServer/trunk/twext/python/sendmsg.c
source_changes at macosforge.org
source_changes at macosforge.org
Tue Apr 16 13:40:11 PDT 2013
Revision: 11045
http://trac.calendarserver.org//changeset/11045
Author: glyph at apple.com
Date: 2013-04-16 13:40:11 -0700 (Tue, 16 Apr 2013)
Log Message:
-----------
Fix message_header.msg_control leaking each time that sendmsg() returns without error. Also, make error-handling logic more uniform and consistent between sendmsg and recvmsg.
Modified Paths:
--------------
CalendarServer/trunk/twext/python/sendmsg.c
Modified: CalendarServer/trunk/twext/python/sendmsg.c
===================================================================
--- CalendarServer/trunk/twext/python/sendmsg.c 2013-04-16 16:11:03 UTC (rev 11044)
+++ CalendarServer/trunk/twext/python/sendmsg.c 2013-04-16 20:40:11 UTC (rev 11045)
@@ -117,6 +117,7 @@
struct msghdr message_header;
struct iovec iov[1];
PyObject *ancillary = NULL;
+ PyObject *ultimate_result = NULL;
static char *kwlist[] = {"fd", "data", "flags", "ancillary", NULL};
if (!PyArg_ParseTupleAndKeywords(
@@ -148,14 +149,14 @@
PyErr_Format(PyExc_TypeError,
"sendmsg argument 3 expected list, got %s",
ancillary->ob_type->tp_name);
- return NULL;
+ goto finished;
}
PyObject *iterator = PyObject_GetIter(ancillary);
PyObject *item = NULL;
if (iterator == NULL) {
- return NULL;
+ goto finished;
}
size_t all_data_len = 0;
@@ -172,7 +173,7 @@
&level, &type, &data, &data_len)) {
Py_DECREF(item);
Py_DECREF(iterator);
- return NULL;
+ goto finished;
}
prev_all_data_len = all_data_len;
@@ -185,7 +186,7 @@
PyErr_Format(PyExc_OverflowError,
"Too much msg_control to fit in a size_t: %zu",
prev_all_data_len);
- return NULL;
+ goto finished;
}
}
@@ -199,15 +200,13 @@
PyErr_Format(PyExc_OverflowError,
"Too much msg_control to fit in a socklen_t: %zu",
all_data_len);
- return NULL;
+ goto finished;
}
message_header.msg_control = malloc(all_data_len);
if (!message_header.msg_control) {
PyErr_NoMemory();
- return NULL;
+ goto finished;
}
- } else {
- message_header.msg_control = NULL;
}
message_header.msg_controllen = (socklen_t) all_data_len;
@@ -215,8 +214,7 @@
item = NULL;
if (!iterator) {
- free(message_header.msg_control);
- return NULL;
+ goto finished;
}
/* Unpack the tuples into the control message. */
@@ -239,8 +237,7 @@
&data_len)) {
Py_DECREF(item);
Py_DECREF(iterator);
- free(message_header.msg_control);
- return NULL;
+ goto finished;
}
control_message->cmsg_level = level;
@@ -250,12 +247,9 @@
if (data_size > SOCKLEN_MAX) {
Py_DECREF(item);
Py_DECREF(iterator);
- free(message_header.msg_control);
-
PyErr_Format(PyExc_OverflowError,
"CMSG_LEN(%zd) > SOCKLEN_MAX", data_len);
-
- return NULL;
+ goto finished;
}
control_message->cmsg_len = (socklen_t) data_size;
@@ -271,8 +265,7 @@
Py_DECREF(iterator);
if (PyErr_Occurred()) {
- free(message_header.msg_control);
- return NULL;
+ goto finished;
}
}
@@ -280,13 +273,16 @@
if (sendmsg_result < 0) {
PyErr_SetFromErrno(sendmsg_socket_error);
- if (message_header.msg_control) {
- free(message_header.msg_control);
- }
- return NULL;
+ goto finished;
+ } else {
+ ultimate_result = Py_BuildValue("n", sendmsg_result);
}
- return Py_BuildValue("n", sendmsg_result);
+ finished:
+ if (message_header.msg_control) {
+ free(message_header.msg_control);
+ }
+ return ultimate_result;
}
static PyObject *sendmsg_recvmsg(PyObject *self, PyObject *args, PyObject *keywds) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130416/d5c6121c/attachment.html>
More information about the calendarserver-changes
mailing list