Skip to content

Commit

Permalink
Fix leak in encode_gc
Browse files Browse the repository at this point in the history
  • Loading branch information
JayKickliter committed May 11, 2020
1 parent c688c1e commit 4d1e413
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions c_src/erasure.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ encode_gc(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[])
}
schedule = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix);
if (schedule == NULL) {
free(shards);
free(matrix);
free(bitmatrix);
return enif_make_badarg(env);
}
jerasure_schedule_encode(k, m, w, schedule, data_ptrs, coding_ptrs, blocksize, blocksize/w);
Expand All @@ -221,6 +224,8 @@ encode_gc(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[])
}
free(shards);
free(matrix);
free(bitmatrix);
jerasure_free_schedule(schedule);
return enif_make_tuple2(env, enif_make_atom(env, "ok"), list);
}

Expand Down Expand Up @@ -575,6 +580,9 @@ decode_gc(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[])

cleanup:

if (bitmatrix != NULL) {
free(bitmatrix);
}
if (matrix != NULL) {
free(matrix);
}
Expand Down

0 comments on commit 4d1e413

Please sign in to comment.