Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit 6d4138c

Browse files
committed
Merged pull request #72
2 parents d6b7aa4 + fc86aa2 commit 6d4138c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/MongoDB/BSON/functions.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,24 @@ Variant HHVM_FUNCTION(MongoDBBsonToJson, const String &data)
9999

100100
str = bson_as_json(b, &str_len);
101101

102+
if (!str) {
103+
bson_reader_destroy(reader);
104+
throw MongoDriver::Utils::throwUnexpectedValueException("Could not convert BSON document to a JSON string");
105+
}
106+
102107
s = String(str_len, ReserveString);
103108
data_s = (unsigned char*) s.bufferSlice().data();
104109
memcpy(data_s, str, str_len);
105110
s.setSize(str_len);
106111

107112
bson_free(str);
108113
} else {
114+
bson_reader_destroy(reader);
109115
throw MongoDriver::Utils::throwUnexpectedValueException("Could not read document from BSON reader");
110-
return Variant();
111116
}
112117

113118
if (bson_reader_read(reader, &eof) || !eof) {
119+
bson_reader_destroy(reader);
114120
throw MongoDriver::Utils::throwUnexpectedValueException("Reading document did not exhaust input buffer");
115121
}
116122

0 commit comments

Comments
 (0)