Skip to content

Commit

Permalink
start patching leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Dirolf committed Feb 6, 2009
1 parent 04e2fc0 commit 3ffc1b5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pymongo/_cbsonmodule.c
Expand Up @@ -299,13 +299,15 @@ static PyObject* _wrap_py_string_as_object(PyObject* string) {
int length = PyString_Size(string) + 5;
char* data = (char*)malloc(length);
if (!data) {
Py_DECREF(string);
PyErr_NoMemory();
return NULL;
}
const char* elements = PyString_AsString(string);
memcpy(data, &length, 4);
memcpy(data + 4, elements, length - 5);
data[length - 1] = 0x00;
Py_DECREF(string);

PyObject* result = Py_BuildValue("s#", data, length);
free(data);
Expand Down Expand Up @@ -598,14 +600,19 @@ static PyObject* _cbson_bson_to_dict(PyObject* self, PyObject* bson) {
return NULL;
}
PyObject* dict = _elements_to_dict(elements);
Py_DECREF(elements);
if (!dict) {
return NULL;
}
PyObject* remainder = PySequence_GetSlice(bson, size, PyString_Size(bson));
if (!remainder) {
Py_DECREF(dict);
return NULL;
}
return Py_BuildValue("OO", dict, remainder);
PyObject* result = Py_BuildValue("OO", dict, remainder);
Py_DECREF(dict);
Py_DECREF(remainder);
return result;
}

static PyMethodDef _CBSONMethods[] = {
Expand Down

0 comments on commit 3ffc1b5

Please sign in to comment.