diff options
author | Mina Farid <minafarid@google.com> | 2018-06-18 11:53:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-18 11:53:30 -0400 |
commit | b97fd69aae5c145bf3d390a9a6d3783eb9584aa5 (patch) | |
tree | a39f07ff79b39c032404119239df16ae54e847b2 /Firestore | |
parent | 063d1e91055a1baf5794f8512cf9589f1f06246b (diff) |
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.
Diffstat (limited to 'Firestore')
-rw-r--r-- | Firestore/core/src/firebase/firestore/nanopb/reader.cc | 3 | ||||
-rw-r--r-- | Firestore/core/src/firebase/firestore/nanopb/reader.h | 1 |
2 files changed, 1 insertions, 3 deletions
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<pb_byte_t*>(&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 ""; } diff --git a/Firestore/core/src/firebase/firestore/nanopb/reader.h b/Firestore/core/src/firebase/firestore/nanopb/reader.h index 2c16ec4..7dd7432 100644 --- a/Firestore/core/src/firebase/firestore/nanopb/reader.h +++ b/Firestore/core/src/firebase/firestore/nanopb/reader.h @@ -150,7 +150,6 @@ T Reader::ReadNestedMessage(const std::function<T(Reader*)>& read_message_fn) { if (!pb_make_string_substream(&stream_, &raw_substream)) { status_ = util::Status(FirestoreErrorCode::DataLoss, PB_GET_ERROR(&stream_)); - pb_close_string_substream(&stream_, &raw_substream); return read_message_fn(this); } Reader substream(raw_substream); |