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

Skip to content

Commit 4a34984

Browse files
committed
plugged copy from bbox leak
svn path=/trunk/matplotlib/; revision=2580
1 parent f9c5c63 commit 4a34984

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/_backend_agg.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ RendererAgg::copy_from_bbox(const Py::Tuple& args) {
639639
*/
640640
int boxwidth = r.x2-r.x1;
641641
int boxheight = r.y2-r.y1;
642-
int boxstride = boxwidth*4;
642+
int boxstride = boxwidth*4;
643643
agg::buffer buf(boxwidth, boxheight, boxstride, false);
644644
if (buf.data ==NULL) {
645645
throw Py::MemoryError("RendererAgg::copy_from_bbox could not allocate memory for buffer");
@@ -652,8 +652,8 @@ RendererAgg::copy_from_bbox(const Py::Tuple& args) {
652652
renderer_base rb(pf);
653653
//rb.clear(agg::rgba(1, 0, 0)); //todo remove me
654654
rb.copy_from(*renderingBuffer, &r, -r.x1, -r.y1);
655-
BufferRegion* reg = new BufferRegion(buf, r);
656-
655+
BufferRegion* reg = new BufferRegion(buf, r, true);
656+
657657
return Py::asObject(reg);
658658

659659

src/_backend_agg.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,19 @@ typedef agg::scanline_bin scanline_bin;
4646
// a class in the swig wrapper
4747
class BufferRegion : public Py::PythonExtension<BufferRegion> {
4848
public:
49-
BufferRegion( agg::buffer& aggbuf, const agg::rect &r) : aggbuf(aggbuf), rect(r) {}
49+
BufferRegion( agg::buffer& aggbuf, const agg::rect &r, bool freemem=true) : aggbuf(aggbuf), rect(r), freemem(freemem) {}
5050
agg::buffer aggbuf;
5151
agg::rect rect;
52+
bool freemem;
5253
Py::Object to_string(const Py::Tuple &args);
5354

5455
static void init_type(void);
5556
virtual ~BufferRegion() {
5657
//std::cout << "buffer region bye bye" << std::endl;
57-
delete [] aggbuf.data;
58-
aggbuf.data = NULL;
58+
if (freemem) {
59+
delete [] aggbuf.data;
60+
aggbuf.data = NULL;
61+
}
5962
};
6063
};
6164

swig/agg_buffer.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ namespace agg {
2424

2525
}
2626
~buffer() {
27-
//std::cout << "bye bye" << std::endl;
28-
if (freemem) delete [] data;
29-
data = NULL;
27+
//std::cout << "bye bye " << freemem << std::endl;
28+
if (freemem) {
29+
delete [] data;
30+
data = NULL;
31+
}
3032
}
3133

3234

0 commit comments

Comments
 (0)