Skip to content

Commit a6c11fa

Browse files
committed
Check if we run out of memory
1 parent 3a76276 commit a6c11fa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

c_src/zstd_nif.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ static ERL_NIF_TERM zstd_nif_flush_compression_stream(ErlNifEnv* env, int argc,
237237
finished = remaining == 0;
238238
if(!finished) {
239239
offset += ZSTD_CStreamOutSize();
240-
enif_realloc_binary(&bin, bin.size + ZSTD_CStreamOutSize());
240+
if(!enif_realloc_binary(&bin, bin.size + ZSTD_CStreamOutSize())) {
241+
enif_release_binary(&bin);
242+
return enif_make_tuple2(env, zstd_atom_error, zstd_atom_enomem);
243+
}
244+
241245
}
242246
} while (!finished);
243247

0 commit comments

Comments
 (0)