From f0fc4f12d6a2dfb14dba09fd4325faae7bdbc9f2 Mon Sep 17 00:00:00 2001 From: Kota Tsuyuzaki Date: Mon, 9 Mar 2015 11:04:14 +0900 Subject: Fix memory leak by alloc internal_payload shss always needs to decode but fragments_to_string will alloc internal_payload as a decoded data. It causes duplicated memory allocation and memory leak. --- src/erasurecode.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/erasurecode.c') diff --git a/src/erasurecode.c b/src/erasurecode.c index 65b4456..129ea4b 100644 --- a/src/erasurecode.c +++ b/src/erasurecode.c @@ -562,18 +562,20 @@ int liberasurecode_decode(int desc, goto out; } - /* - * Try to re-assebmle the original data before attempting a decode - */ - ret = fragments_to_string(k, m, - available_fragments, num_fragments, - out_data, out_data_len); - - /* shss (ntt_backend) must force to decode */ - // TODO: Add a frag and function to handle whether the backend want to decode or not. - if (ret == 0 && instance->common.id != 5) { - /* We were able to get the original data without decoding! */ - goto out; + if (instance->common.id != 5) { + /* shss (ntt_backend) must force to decode */ + // TODO: Add a frag and function to handle whether the backend want to decode or not. + /* + * Try to re-assebmle the original data before attempting a decode + */ + ret = fragments_to_string(k, m, + available_fragments, num_fragments, + out_data, out_data_len); + + if (ret == 0) { + /* We were able to get the original data without decoding! */ + goto out; + } } /* -- cgit v1.2.1