Skip to content

Commit

Permalink
Check for malloc failure in yajl_lex_alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
jhawthorn committed Apr 4, 2022
1 parent 36410d5 commit b99748f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ext/yajl/yajl.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,13 @@ yajl_alloc(const yajl_callbacks * callbacks,

hand->callbacks = callbacks;
hand->ctx = ctx;
hand->lexer = yajl_lex_alloc(&(hand->alloc), allowComments, validateUTF8); // fixme: check allocation
hand->lexer = yajl_lex_alloc(&(hand->alloc), allowComments, validateUTF8);
if (!hand->lexer) {
YA_FREE(afs, hand);
return NULL;
}
hand->bytesConsumed = 0;
hand->decodeBuf = yajl_buf_alloc(&(hand->alloc)); // fixme: check allocation
hand->decodeBuf = yajl_buf_alloc(&(hand->alloc));
yajl_bs_init(hand->stateStack, &(hand->alloc));

if (yajl_bs_push(hand->stateStack, yajl_state_start)) {
Expand Down
2 changes: 2 additions & 0 deletions ext/yajl/yajl_lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ yajl_lex_alloc(yajl_alloc_funcs * alloc,
unsigned int allowComments, unsigned int validateUTF8)
{
yajl_lexer lxr = (yajl_lexer) YA_MALLOC(alloc, sizeof(struct yajl_lexer_t));
if (!lxr)
return NULL;
memset((void *) lxr, 0, sizeof(struct yajl_lexer_t));
lxr->buf = yajl_buf_alloc(alloc);
lxr->allowComments = allowComments;
Expand Down

0 comments on commit b99748f

Please sign in to comment.