summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsk Solem Hoel <ask@celeryproject.org>2016-03-22 11:17:36 -0700
committerAsk Solem Hoel <ask@celeryproject.org>2016-03-22 11:17:36 -0700
commit8939e477e39ca9604c344220447b88f51f66da00 (patch)
treea468e0552b5cee06dcd3c15baa9476e8b0f9540e
parentf5634808758139265656d2a840f38060ee952336 (diff)
parent73d66a9f5ea9b9f72e497015be3c765f7cebd10f (diff)
downloadlibrabbitmq-8939e477e39ca9604c344220447b88f51f66da00.tar.gz
Merge pull request #47 from rogerhu/fix_hostname_corruption
Fix issues with hostname corruption when Python strings go out of scope.
-rw-r--r--Modules/_librabbitmq/connection.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/Modules/_librabbitmq/connection.c b/Modules/_librabbitmq/connection.c
index 8b26a10..6626e47 100644
--- a/Modules/_librabbitmq/connection.c
+++ b/Modules/_librabbitmq/connection.c
@@ -935,6 +935,19 @@ PyRabbitMQ_ConnectionType_dealloc(PyRabbitMQ_Connection *self)
{
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject*)self);
+
+ if (self->hostname != NULL)
+ PyMem_Free(self->hostname);
+
+ if (self->userid != NULL)
+ PyMem_Free(self->userid);
+
+ if (self->password != NULL)
+ PyMem_Free(self->password);
+
+ if (self->virtual_host != NULL)
+ PyMem_Free(self->virtual_host);
+
Py_XDECREF(self->callbacks);
Py_XDECREF(self->client_properties);
Py_XDECREF(self->server_properties);
@@ -961,10 +974,11 @@ PyRabbitMQ_ConnectionType_init(PyRabbitMQ_Connection *self,
"client_properties",
NULL
};
- char *hostname = "localhost";
- char *userid = "guest";
- char *password = "guest";
- char *virtual_host = "/";
+ char *hostname;
+ char *userid;
+ char *password;
+ char *virtual_host;
+
int channel_max = 0xffff;
int frame_max = 131072;
int heartbeat = 0;
@@ -977,10 +991,20 @@ PyRabbitMQ_ConnectionType_init(PyRabbitMQ_Connection *self,
return -1;
}
- self->hostname = hostname;
- self->userid = userid;
- self->password = password;
- self->virtual_host = virtual_host;
+ self->hostname = PyMem_Malloc(strlen(hostname) + 1);
+ self->userid = PyMem_Malloc(strlen(userid) + 1);
+ self->password = PyMem_Malloc(strlen(password) + 1);
+ self->virtual_host = PyMem_Malloc(strlen(virtual_host) + 1);
+
+ if (self->hostname == NULL || self->userid == NULL || self->password == NULL || self->virtual_host == NULL) {
+ return PyErr_NoMemory();
+ }
+
+ strcpy(self->hostname, hostname);
+ strcpy(self->userid, userid);
+ strcpy(self->password, password);
+ strcpy(self->virtual_host, virtual_host);
+
self->port = port;
self->channel_max = channel_max;
self->frame_max = frame_max;