From b97fd69aae5c145bf3d390a9a6d3783eb9584aa5 Mon Sep 17 00:00:00 2001 From: Mina Farid Date: Mon, 18 Jun 2018 11:53:30 -0400 Subject: Avoid closing unintialized substreams (#1411) * A substream should not be closed if pb_make_string_substream() failed to create it and returned false. * Fixed a potential wrong error message. --- Firestore/core/src/firebase/firestore/nanopb/reader.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Firestore/core/src/firebase/firestore/nanopb/reader.cc') diff --git a/Firestore/core/src/firebase/firestore/nanopb/reader.cc b/Firestore/core/src/firebase/firestore/nanopb/reader.cc index 69e3d83..3b102f0 100644 --- a/Firestore/core/src/firebase/firestore/nanopb/reader.cc +++ b/Firestore/core/src/firebase/firestore/nanopb/reader.cc @@ -110,14 +110,13 @@ std::string Reader::ReadString() { pb_istream_t substream; if (!pb_make_string_substream(&stream_, &substream)) { status_ = Status(FirestoreErrorCode::DataLoss, PB_GET_ERROR(&stream_)); - pb_close_string_substream(&stream_, &substream); return ""; } std::string result(substream.bytes_left, '\0'); if (!pb_read(&substream, reinterpret_cast(&result[0]), substream.bytes_left)) { - status_ = Status(FirestoreErrorCode::DataLoss, PB_GET_ERROR(&stream_)); + status_ = Status(FirestoreErrorCode::DataLoss, PB_GET_ERROR(&substream)); pb_close_string_substream(&stream_, &substream); return ""; } -- cgit v1.2.3