Revision: 4713
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4713&view=rev
Author: mdboom
Date: 2007-12-12 11:07:03 -0800 (Wed, 12 Dec 2007)
Log Message:
-----------
Fix reference-counting leak when saving an Agg Png to a file-like object.
Modified Paths:
--------------
trunk/matplotlib/src/_backend_agg.cpp
Modified: trunk/matplotlib/src/_backend_agg.cpp
===================================================================
--- trunk/matplotlib/src/_backend_agg.cpp 2007-12-12 18:24:56 UTC (rev
4712)
+++ trunk/matplotlib/src/_backend_agg.cpp 2007-12-12 19:07:03 UTC (rev
4713)
@@ -2261,17 +2261,21 @@
static void write_png_data(png_structp png_ptr, png_bytep data, png_size_t
length) {
PyObject* py_file_obj = (PyObject*)png_get_io_ptr(png_ptr);
PyObject* write_method = PyObject_GetAttrString(py_file_obj, "write");
- PyObject_CallFunction(write_method, "s#", data, length);
-
- // MGDTODO: Check NULL on failure
+ PyObject* result = NULL;
+ if (write_method)
+ result = PyObject_CallFunction(write_method, "s#", data, length);
+ Py_XDECREF(write_method);
+ Py_XDECREF(result);
}
static void flush_png_data(png_structp png_ptr) {
PyObject* py_file_obj = (PyObject*)png_get_io_ptr(png_ptr);
PyObject* flush_method = PyObject_GetAttrString(py_file_obj, "flush");
- if (flush_method) {
- PyObject_CallFunction(flush_method, "");
- }
+ PyObject* result = NULL;
+ if (flush_method)
+ result = PyObject_CallFunction(flush_method, "");
+ Py_XDECREF(flush_method);
+ Py_XDECREF(result);
}
// this code is heavily adapted from the paint license, which is in
@@ -2294,8 +2298,11 @@
}
else {
PyObject* write_method = PyObject_GetAttrString(py_fileobj.ptr(), "write");
- if (!(write_method && PyCallable_Check(write_method)))
+ if (!(write_method && PyCallable_Check(write_method))) {
+ Py_XDECREF(write_method);
throw Py::TypeError("Object does not appear to be a path or a Python
file-like object");
+ }
+ Py_XDECREF(write_method);
}
png_bytep *row_pointers = NULL;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins