diff --git a/libbitdht/src/bitdht/bencode.c b/libbitdht/src/bitdht/bencode.c index 598dc7615..2a486daca 100644 --- a/libbitdht/src/bitdht/bencode.c +++ b/libbitdht/src/bitdht/bencode.c @@ -209,7 +209,10 @@ static be_node *_be_decode(const char **data, long long *data_len) #ifdef BE_DEBUG_DECODE fprintf(stderr, "bencode::_be_decode() dictionary get val\n"); #endif - ret->val.d[i].val = _be_decode(data, data_len); + ret->val.d[i ].val = _be_decode(data, data_len); + ret->val.d[i+1].val = NULL ; // ensures termination of loops based on 0x0 value, otherwise, uninitialized + // memory occurs if(ret->val.d[i].key == 0x0 && ret->val.d[i].val != NULL) + // when calling be_free 8 lines below this point... if ((ret->val.d[i].key == NULL) || (ret->val.d[i].val == NULL)) {