Skip to content

Commit

Permalink
Fix reference leak in instance attribute error handling, add more error
Browse files Browse the repository at this point in the history
handling tests.
  • Loading branch information
andrewm committed Jun 13, 2007
1 parent cc9465f commit a144950
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
3 changes: 0 additions & 3 deletions chutney.c
Expand Up @@ -171,9 +171,6 @@ object_build(void *objraw, void *stateraw)
finally:
Py_XDECREF(dict);
Py_DECREF(state);
if (res < 0) {
Py_DECREF(obj);
}
return res;
}

Expand Down
8 changes: 6 additions & 2 deletions chutney/chutneyparse.c
Expand Up @@ -397,10 +397,14 @@ object_build(chutney_load_state *state)

if ((objstate = STACK_POP(state)) == NULL)
return CHUTNEY_STACK_ERR;
if ((obj = STACK_POP(state)) == NULL)
if ((obj = STACK_POP(state)) == NULL) {
state->callbacks.dealloc(objstate);
return CHUTNEY_STACK_ERR;
if (state->callbacks.object_build(obj, objstate) < 0)
}
if (state->callbacks.object_build(obj, objstate) < 0) {
state->callbacks.dealloc(obj);
return CHUTNEY_CALLBACK_ERR;
}
return stack_push(state, obj);
}

Expand Down
23 changes: 20 additions & 3 deletions tests.py
Expand Up @@ -212,15 +212,31 @@ def test_dict(self):
# SETITEMS on a tuple, rather than a dict
self.assertRaises(TypeError, chutney.loads, '(t(NNu.')

def test_inst(self):
# Error handling
def test_inst_err(self):
# Missing module and global name
self.assertRaises(EOFError, chutney.loads, 'c.')
# Missing module name
self.assertRaises(NameError, chutney.loads, 'c\nTestInstance\n.')
# Missing global name
self.assertRaises(AttributeError, chutney.loads, 'c__main__\n\n.')
# global isn't a class
self.assertRaises(chutney.UnpicklingError, chutney.loads,
'(csys\npath\no.')
# inst dict is wrong type
self.assertRaises(chutney.UnpicklingError, chutney.loads,
'(c__main__\nTestInstance\noNb.')
# Old-style class
# BUILD with not enough objects on stack
self.assertRaises(chutney.UnpicklingError, chutney.loads,
'b.')
self.assertRaises(chutney.UnpicklingError, chutney.loads,
'Nb.')
# BUILD with no object
self.assertRaises(chutney.UnpicklingError, chutney.loads,
'NNb.')
self.assertRaises(AttributeError, chutney.loads,
'N}b.')

def test_inst(self):
self.assertEqual(chutney.loads('c__main__\nTestInstance\n.'),
TestInstance)
o = chutney.loads('(c__main__\nTestInstance\no.')
Expand Down Expand Up @@ -259,6 +275,7 @@ class LoadSuite(unittest.TestSuite):
'test_unicode',
'test_tuple',
'test_dict',
'test_inst_err',
'test_inst',
'test_obj',
]
Expand Down

0 comments on commit a144950

Please sign in to comment.