Handle allocation failures when instantiating documents

This commit is contained in:
Max Brunsfeld 2016-01-18 10:44:49 -08:00
parent 9d0835edbf
commit 1543a6c7b0
12 changed files with 255 additions and 31 deletions

View file

@ -7,9 +7,16 @@
#include "runtime/document.h"
TSDocument *ts_document_make() {
TSDocument *document = ts_calloc(1, sizeof(TSDocument));
document->parser = ts_parser_make();
return document;
TSDocument *self = ts_calloc(1, sizeof(TSDocument));
if (!self)
return NULL;
if (!ts_parser_init(&self->parser)) {
ts_free(self);
return NULL;
}
return self;
}
void ts_document_free(TSDocument *self) {