-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory leaks in the temporary rasterized images.
- Loading branch information
Showing
2 changed files
with
10 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1557,6 +1557,7 @@ RendererAgg::_draw_path_collection_generic | |
|
||
if ((Nfacecolors == 0 && Nedgecolors == 0) || Npaths == 0) | ||
{ | ||
Py_XDECREF(transforms_arr); | ||
return Py::Object(); | ||
} | ||
|
||
|
@@ -1708,6 +1709,8 @@ RendererAgg::_draw_path_collection_generic | |
} | ||
} | ||
|
||
Py_XDECREF(transforms_arr); | ||
|
||
return Py::Object(); | ||
} | ||
|
||
|
@@ -2383,11 +2386,7 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args) | |
|
||
int newwidth = 0; | ||
int newheight = 0; | ||
#if PY3K | ||
Py::Bytes data; | ||
#else | ||
Py::String data; | ||
#endif | ||
PyObject *data; | ||
|
||
if (xmin < xmax && ymin < ymax) | ||
{ | ||
|
@@ -2406,18 +2405,12 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args) | |
// the _AsString() API. | ||
unsigned int* dst; | ||
|
||
#if PY3K | ||
data = Py::Bytes(static_cast<const char*>(NULL), (int) newsize); | ||
dst = reinterpret_cast<unsigned int*>(PyBytes_AsString(data.ptr())); | ||
#else | ||
data = Py::String(static_cast<const char*>(NULL), (int) newsize); | ||
dst = reinterpret_cast<unsigned int*>(PyString_AsString(data.ptr())); | ||
#endif | ||
|
||
if (dst == NULL) | ||
data = PyBytes_FromStringAndSize(NULL, newsize); | ||
if (data == NULL) | ||
{ | ||
throw Py::MemoryError("RendererAgg::tostring_minimized could not allocate memory"); | ||
} | ||
dst = (unsigned int *)PyBytes_AsString(data); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mdboom
Author
Member
|
||
|
||
unsigned int* src = (unsigned int*)pixBuffer; | ||
for (int y = ymin; y < ymax; ++y) | ||
|
@@ -2436,7 +2429,8 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args) | |
bounds[3] = Py::Int(newheight); | ||
|
||
Py::Tuple result(2); | ||
result[0] = data; | ||
result[0] = Py::Object(data, false); | ||
Py_DECREF(data); | ||
result[1] = bounds; | ||
|
||
return result; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is subtly different from the original code. In 2.x, this would be PyString_AsString(), now it is always PyBytes_AsString() (which would match with PyBytes_FromStringAndSize(). However, the data pointer is now a PyObject pointer, not a Py::Bytes pointer. Could this cause issues?