Skip to content

Commit 5d7b560

Browse files
authored
Merge pull request #1636 from evoskuil/master
Fix leak in chain::operation with invalid construct.
2 parents cf79677 + 1b0c224 commit 5d7b560

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

Diff for: src/chain/operation.cpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -221,25 +221,23 @@ void operation::assign_data(reader& source) NOEXCEPT
221221
source.invalidate();
222222

223223
// An invalid source.read_bytes_raw returns nullptr.
224-
INPLACE(&data_, data_chunk, allocator, source.read_bytes_raw(size));
224+
const auto ptr = source.read_bytes_raw(size);
225225
underflow_ = !source;
226+
if (!underflow_)
227+
{
228+
INPLACE(&data_, data_chunk, allocator, ptr);
229+
return;
230+
}
226231

227232
// This requires that provided stream terminates at the end of the script.
228233
// When passing ops as part of a stream longer than the script, such as for
229234
// a transaction, caller should apply source.set_limit(prefix_size), and
230235
// clear the stream limit upon return. Stream invalidation and set_position
231236
// do not alter a stream limit, it just behaves as a smaller stream buffer.
232237
// Without a limit, source.read_bytes() below consumes the remaining stream.
233-
if (underflow_)
234-
{
235-
code_ = any_invalid;
236-
source.set_position(start);
237-
238-
// An invalid source.read_bytes_raw returns nullptr.
239-
INPLACE(&data_, data_chunk, allocator, source.read_bytes_raw());
240-
}
241-
242-
// All byte vectors are deserializable, stream indicates own failure.
238+
code_ = any_invalid;
239+
source.set_position(start);
240+
INPLACE(&data_, data_chunk, allocator, source.read_bytes_raw());
243241
}
244242

245243
// static/private

0 commit comments

Comments
 (0)