Skip to content

Commit be07f99

Browse files
committed
Error out if memory allocation for context fails
1 parent f6a100e commit be07f99

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/sass_context.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ extern "C" {
330330
c_ctx->error_column = std::string::npos;
331331

332332
// allocate a new compiler instance
333-
Sass_Compiler* compiler = (struct Sass_Compiler*) calloc(1, sizeof(struct Sass_Compiler));
333+
void* ctxmem = calloc(1, sizeof(struct Sass_Compiler));
334+
if (ctxmem == 0) { std::cerr << "Error allocating memory for context" << std::endl; return 0; }
335+
Sass_Compiler* compiler = (struct Sass_Compiler*) ctxmem;
334336
compiler->state = SASS_COMPILER_CREATED;
335337

336338
// store in sass compiler

0 commit comments

Comments
 (0)