Skip to content

Commit 867b3b2

Browse files
committed
Only free _parser if not null.
Fixes a segfault if an invalid vendor is passed in.
1 parent a17e0c9 commit 867b3b2

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎Parser.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ void Parser_init_type(PyObject *m) {
1414
void Parser_dealloc(Parser *self)
1515
{
1616
//printf("Parser_dealloc\n");
17-
gsp_parser_free(self->_parser);
18-
self->ob_type->tp_free((PyObject*)self);
17+
if (self->_parser != NULL) {
18+
gsp_parser_free(self->_parser);
19+
}
20+
self->ob_type->tp_free((PyObject*)self);
1921
}
2022

2123
// Allocate new Parser object
@@ -135,4 +137,4 @@ PyObject* Parser_get_statement_count(PyObject* self, PyObject* args)
135137
n = PyLong_FromLong(parser->_parser->nStatement);
136138

137139
return n;
138-
}
140+
}

0 commit comments

Comments
 (0)