From 6e03da594a58e764f5565f50edad2fd5c0595c7e Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Thu, 20 Jan 2022 15:07:23 +0800 Subject: [PATCH] [test]: Fix mpi_rc2_test crash on help Change-Id: I1a6568b03ca27e7795ae4e994fd497ad49f50c02 Signed-off-by: Herman Chen --- test/mpi_enc_test.c | 1 - test/mpi_rc2_test.c | 20 ++++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/test/mpi_enc_test.c b/test/mpi_enc_test.c index 71f05080..d5513d55 100644 --- a/test/mpi_enc_test.c +++ b/test/mpi_enc_test.c @@ -991,4 +991,3 @@ DONE: return ret; } - diff --git a/test/mpi_rc2_test.c b/test/mpi_rc2_test.c index cfb0e64b..1e66b783 100644 --- a/test/mpi_rc2_test.c +++ b/test/mpi_rc2_test.c @@ -1126,7 +1126,7 @@ MPP_TEST_OUT: int main(int argc, char **argv) { MpiEncTestArgs* enc_cmd = mpi_enc_test_cmd_get(); - MpiRc2TestCtx ctx; + MpiRc2TestCtx *ctx = NULL; MPP_RET ret = MPP_OK; ret = mpi_enc_test_cmd_update_by_args(enc_cmd, argc, argv); @@ -1135,21 +1135,29 @@ int main(int argc, char **argv) mpi_enc_test_cmd_show_opt(enc_cmd); - memset(&ctx, 0, sizeof(ctx)); - ctx.enc_cmd = enc_cmd; + ctx = mpp_calloc(MpiRc2TestCtx, 1); + if (NULL == ctx) { + ret = MPP_ERR_MALLOC; + goto DONE; + } - ret = mpi_rc_init(&ctx); + ctx->enc_cmd = enc_cmd; + + ret = mpi_rc_init(ctx); if (ret) { mpp_err("mpi_rc_init failded ret %d", ret); goto DONE; } - ret = mpi_rc_codec(&ctx); + ret = mpi_rc_codec(ctx); if (ret) mpp_err("mpi_rc_codec failded ret %d", ret); DONE: - mpi_rc_deinit(&ctx); + if (ctx) { + mpi_rc_deinit(ctx); + ctx = NULL; + } mpi_enc_test_cmd_put(enc_cmd);