Jerasure: Handle initialization errors correctly

Otherwise we can get backtraces where we try to free something that was
never initialized.

Change-Id: Iaea427b977fd20819e2da5678cc4889d3a42dd65
This commit is contained in:
Tim Burke 2017-01-25 23:40:32 +00:00
parent 4ab1336cab
commit 842b4a9bd7
2 changed files with 34 additions and 8 deletions

View File

@ -357,17 +357,21 @@ static void * jerasure_rs_cauchy_init(struct ec_backend_args *args,
}
desc->bitmatrix = desc->jerasure_matrix_to_bitmatrix(k, m, w, desc->matrix);
if (NULL == desc->bitmatrix) {
goto error;
goto bitmatrix_error;
}
desc->schedule = desc->jerasure_smart_bitmatrix_to_schedule(k, m, w, desc->bitmatrix);
if (NULL == desc->schedule) {
goto error;
goto schedule_error;
}
return desc;
schedule_error:
free(desc->bitmatrix);
bitmatrix_error:
free(desc->matrix);
error:
free_rs_cauchy_desc(desc);
free(desc);
return NULL;
}

View File

@ -1416,8 +1416,7 @@ static void test_decode_with_missing_multi_data_parity(
}
}
static void test_decode_reconstruct_specific_error_case(
const ec_backend_id_t be_id, struct ec_args *args)
static void test_isa_l_rs_vand_decode_reconstruct_specific_error_case()
{
struct ec_args specific_1010_args = {
.k = 10,
@ -1511,6 +1510,25 @@ static void test_decode_reconstruct_specific_error_case(
free(skips);
}
static void test_jerasure_rs_cauchy_init_failure()
{
struct ec_args bad_args = {
.k = 10,
.m = 10,
.w = 4,
};
// NB: (k + m) > (1 << w) => too many frags!
int desc = -1;
desc = liberasurecode_instance_create(
EC_BACKEND_JERASURE_RS_CAUCHY, &bad_args);
if (-EBACKENDNOTAVAIL == desc) {
fprintf (stderr, "Backend library not available!\n");
return;
}
assert(-EBACKENDINITERR == desc);
}
static void test_simple_encode_decode(const ec_backend_id_t be_id,
struct ec_args *args)
{
@ -1991,6 +2009,10 @@ struct testcase testcases[] = {
test_verify_stripe_metadata_frag_idx_invalid,
EC_BACKEND_JERASURE_RS_CAUCHY, CHKSUM_CRC32,
.skip = false},
{"test_jerasure_rs_cauchy_init_failure",
test_jerasure_rs_cauchy_init_failure,
EC_BACKENDS_MAX, 0,
.skip = false},
// ISA-L rs_vand tests
{"create_and_destroy_backend",
test_create_and_destroy_backend,
@ -2052,10 +2074,10 @@ struct testcase testcases[] = {
test_verify_stripe_metadata_frag_idx_invalid,
EC_BACKEND_ISA_L_RS_VAND, CHKSUM_CRC32,
.skip = false},
{"test_isa_l_decode_reconstruct_specific_error_case",
test_decode_reconstruct_specific_error_case,
{"test_isa_l_rs_vand_decode_reconstruct_specific_error_case",
test_isa_l_rs_vand_decode_reconstruct_specific_error_case,
EC_BACKENDS_MAX, 0, // note this test is using ISA-L in hard coded
.skip = false},
.skip = false},
// ISA-L rs cauchy tests
{"create_and_destroy_backend",
test_create_and_destroy_backend,