Skip to content

Commit

Permalink
Merge pull request #6 from helium/jsk/fix-leak
Browse files Browse the repository at this point in the history
Fix leak in encode_gc()
  • Loading branch information
Vagabond authored May 12, 2020
2 parents c688c1e + 4d1e413 commit 5f53128
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 5f53128

Please sign in to comment.