Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 255eb33

Browse files
committed
Merged revisions 4707-4714 via svnmerge from
http://matplotlib.svn.sf.net/svnroot/matplotlib/trunk/matplotlib ........ r4707 | mdboom | 2007-12-12 09:52:01 -0500 (Wed, 12 Dec 2007) | 2 lines Support fontconfig syntax in Text constructor. ........ r4713 | mdboom | 2007-12-12 14:07:03 -0500 (Wed, 12 Dec 2007) | 2 lines Fix reference-counting leak when saving an Agg Png to a file-like object. ........ svn path=/branches/transforms/; revision=4715
1 parent e8e95d8 commit 255eb33

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

src/_backend_agg.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,17 +1289,21 @@ RendererAgg::write_rgba(const Py::Tuple& args) {
12891289
static void write_png_data(png_structp png_ptr, png_bytep data, png_size_t length) {
12901290
PyObject* py_file_obj = (PyObject*)png_get_io_ptr(png_ptr);
12911291
PyObject* write_method = PyObject_GetAttrString(py_file_obj, "write");
1292-
PyObject_CallFunction(write_method, "s#", data, length);
1293-
1294-
// MGDTODO: Check NULL on failure
1292+
PyObject* result = NULL;
1293+
if (write_method)
1294+
result = PyObject_CallFunction(write_method, "s#", data, length);
1295+
Py_XDECREF(write_method);
1296+
Py_XDECREF(result);
12951297
}
12961298

12971299
static void flush_png_data(png_structp png_ptr) {
12981300
PyObject* py_file_obj = (PyObject*)png_get_io_ptr(png_ptr);
12991301
PyObject* flush_method = PyObject_GetAttrString(py_file_obj, "flush");
1300-
if (flush_method) {
1301-
PyObject_CallFunction(flush_method, "");
1302-
}
1302+
PyObject* result = NULL;
1303+
if (flush_method)
1304+
result = PyObject_CallFunction(flush_method, "");
1305+
Py_XDECREF(flush_method);
1306+
Py_XDECREF(result);
13031307
}
13041308

13051309
// this code is heavily adapted from the paint license, which is in
@@ -1322,8 +1326,11 @@ RendererAgg::write_png(const Py::Tuple& args)
13221326
}
13231327
else {
13241328
PyObject* write_method = PyObject_GetAttrString(py_fileobj.ptr(), "write");
1325-
if (!(write_method && PyCallable_Check(write_method)))
1329+
if (!(write_method && PyCallable_Check(write_method))) {
1330+
Py_XDECREF(write_method);
13261331
throw Py::TypeError("Object does not appear to be a path or a Python file-like object");
1332+
}
1333+
Py_XDECREF(write_method);
13271334
}
13281335

13291336
png_bytep *row_pointers = NULL;

0 commit comments

Comments
 (0)