Skip to content

Commit 90ce6f1

Browse files
committed
Avoid crashes when .available() is called by detecting that underlying stream has closed.
1 parent 02cfb98 commit 90ce6f1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Firebase.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,15 @@ FirebaseStream::FirebaseStream(const std::string& host, const std::string& auth,
193193
}
194194

195195
bool FirebaseStream::available() {
196-
return http_->getStreamPtr()->available();
196+
auto client = http_->getStreamPtr();
197+
return (client == nullptr) ? false : client->available();
197198
}
198199

199200
FirebaseStream::Event FirebaseStream::read(std::string& event) {
200201
auto client = http_->getStreamPtr();
202+
if (client == nullptr) {
203+
return Event();
204+
}
201205
Event type;
202206
std::string typeStr = client->readStringUntil('\n').substring(7).c_str();
203207
if (typeStr == "put") {

src/FirebaseArduino.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,15 @@ void FirebaseArduino::stream(const String& path) {
131131
}
132132

133133
bool FirebaseArduino::available() {
134-
return http_->getStreamPtr()->available();
134+
auto client = http_->getStreamPtr();
135+
return (client == nullptr) ? false : client->available();
135136
}
136137

137138
FirebaseObject FirebaseArduino::readEvent() {
138139
auto client = http_->getStreamPtr();
140+
if (client == nullptr) {
141+
return FirebaseObject("");
142+
}
139143
String type = client->readStringUntil('\n').substring(7);;
140144
String event = client->readStringUntil('\n').substring(6);
141145
client->readStringUntil('\n'); // consume separator

0 commit comments

Comments
 (0)