Skip to content

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagabond committed Oct 23, 2018
1 parent ec0eeee commit 2289eda
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion c_src/erasure.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ encode(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[])
), list);
}
free(shards);
free(matrix);
return enif_make_tuple2(env, enif_make_atom(env, "ok"), list);
}

Expand All @@ -132,6 +133,7 @@ decode(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[])
return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_atom(env, "insufficent_shards"));
}

int *matrix = NULL;
char *shards = NULL;
char *data_ptrs[k];
char *coding_ptrs[m];
Expand Down Expand Up @@ -235,7 +237,7 @@ decode(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[])
erasures[j] = -1;

int w = 8;
int *matrix = reed_sol_vandermonde_coding_matrix(k, m, w);
matrix = reed_sol_vandermonde_coding_matrix(k, m, w);
int res = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data_ptrs, coding_ptrs, blocksize);
//abort();

Expand Down Expand Up @@ -263,6 +265,9 @@ decode(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[])

cleanup:

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

0 comments on commit 2289eda

Please sign in to comment.