Skip to content

Commit 18bfce9

Browse files
committed
Surface scope encoding errors from phongo_javascript_init
When phongo_zval_to_bson throws while encoding the scope, release the already-allocated code buffer and the partially-written scope BSON, and report failure to the caller. Previously the function returned true even though intern was left in an inconsistent state.
1 parent 8c5e254 commit 18bfce9

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/BSON/Javascript.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ static bool phongo_javascript_init(phongo_javascript_t* intern, const char* code
4646
if (scope && (Z_TYPE_P(scope) == IS_OBJECT || Z_TYPE_P(scope) == IS_ARRAY)) {
4747
intern->scope = bson_new();
4848
phongo_zval_to_bson(scope, PHONGO_BSON_NONE, intern->scope, NULL);
49+
50+
if (EG(exception)) {
51+
efree(intern->code);
52+
intern->code = NULL;
53+
bson_destroy(intern->scope);
54+
intern->scope = NULL;
55+
return false;
56+
}
4957
} else {
5058
intern->scope = NULL;
5159
}

0 commit comments

Comments
 (0)