未验证 提交 d74aa39f 编写于 作者: N Ning Yu 提交者: GitHub

zstd: check for OOM when creating {C,D}Ctx

ZSTD creates CCtx and DCtx with malloc() by default, a NULL pointer will
be returned on OOM, the callers must check for NULL pointers.

Also fixed a typo in the comment.

Fixes: https://github.com/greenplum-db/gpdb/issues/9294

Reported-by: shellboy
Reviewed-by: NZhenghua Lyu <zlv@pivotal.io>
上级 48fe471d
......@@ -70,6 +70,11 @@ zstd_constructor(PG_FUNCTION_ARGS)
state->ctx->cctx = ZSTD_createCCtx();
state->ctx->dctx = ZSTD_createDCtx();
if (!state->ctx->cctx)
elog(ERROR, "out of memory");
if (!state->ctx->dctx)
elog(ERROR, "out of memory");
PG_RETURN_POINTER(cs);
}
......
......@@ -988,6 +988,8 @@ BufFileStartCompression(BufFile *file)
file->zstd_context = zstd_alloc_context();
file->zstd_context->cctx = ZSTD_createCStream();
if (!file->zstd_context->cctx)
elog(ERROR, "out of memory");
ZSTD_initCStream(file->zstd_context->cctx, BUFFILE_ZSTD_COMPRESSION_LEVEL);
CurrentResourceOwner = oldowner;
......@@ -1068,6 +1070,8 @@ BufFileEndCompression(BufFile *file)
/* Done writing. Initialize for reading */
file->zstd_context->dctx = ZSTD_createDStream();
if (!file->zstd_context->dctx)
elog(ERROR, "out of memory");
ZSTD_initDStream(file->zstd_context->dctx);
file->compressed_buffer.src = palloc(BLCKSZ);
......
......@@ -54,11 +54,14 @@ extern void gp_decompress(
* To use:
*
* zstd_context *ctx = call zstd_alloc_context();
*
* ctx->cctx = ZSTD_createCCtx();
* if (!ctx->cctx)
* elog(ERROR, "out of memory");
*
* <use the context using normal ZSTD functions>
*
* zsd_free_context(ctx);
* zstd_free_context(ctx);
*
* If the transaction is aborted, the handle will be automatically closed,
* when the resource owner is destroyed.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册