Commit b85cb05f authored by Marius Wachtler's avatar Marius Wachtler

BoxIteratorGeneric: fix leak when next() throwes in the constructor

parent 36894806
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
namespace pyston { namespace pyston {
namespace { namespace {
static std::string next_str("next");
class BoxIteratorGeneric : public BoxIteratorImpl { class BoxIteratorGeneric : public BoxIteratorImpl {
private: private:
Box* iterator; Box* iterator;
...@@ -31,9 +29,17 @@ public: ...@@ -31,9 +29,17 @@ public:
if (container) { if (container) {
// TODO: this should probably call getPystonIter // TODO: this should probably call getPystonIter
iterator = getiter(container); iterator = getiter(container);
if (iterator) if (iterator) {
// try catch block to manually decref the iterator because if the constructor throwes the destructor
// won't get called
// but we should probably just change the code to not call next inside the constructor...
try {
next(); next();
else } catch (ExcInfo e) {
Py_CLEAR(iterator);
throw e;
}
} else
*this = *end(); *this = *end();
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment