Skip to content

Commit

Permalink
BUG: don't segfault in tokenizer cleanup if initializing file reader …
Browse files Browse the repository at this point in the history
…failed. close #2474
  • Loading branch information
wesm committed Dec 10, 2012
1 parent 223a1fd commit dd7218c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,9 @@ def test_decompression(self):

result = self.read_csv('__tmp__', compression='bz2')
tm.assert_frame_equal(result, expected)

self.assertRaises(ValueError, self.read_csv,
'__tmp__', compression='bz3')
finally:
try:
os.remove('__tmp__')
Expand Down
3 changes: 3 additions & 0 deletions pandas/src/parser.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ cdef class TextReader:
int status
void *ptr

self.parser.cb_io = NULL
self.parser.cb_cleanup = NULL

if isinstance(source, basestring) and self.compression:
if self.compression == 'gzip':
import gzip
Expand Down
4 changes: 4 additions & 0 deletions pandas/src/parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ int parser_clear_data_buffers(parser_t *self) {
}

int parser_cleanup(parser_t *self) {
if (self->cb_cleanup == NULL) {
return 0;
}

if (self->cb_cleanup(self->source) < 0) {
return -1;
}
Expand Down

0 comments on commit dd7218c

Please sign in to comment.