Skip to content

Commit 3036797

Browse files
committed
Use consistent memory allocation for write error messages
These strings were released with efree() in the object destructors and should be allocated with emalloc().
1 parent 29e5121 commit 3036797

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

php_phongo.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,10 @@ zend_bool phongo_writeconcernerror_init(zval *return_value, bson_t *bson TSRMLS_
477477
writeconcernerror->code = bson_iter_int32(&iter);
478478
}
479479
if (bson_iter_init_find(&iter, bson, "errmsg") && BSON_ITER_HOLDS_UTF8(&iter)) {
480-
writeconcernerror->message = bson_iter_dup_utf8(&iter, NULL);
480+
uint32_t errmsg_len;
481+
const char *err_msg = bson_iter_utf8(&iter, &errmsg_len);
482+
483+
writeconcernerror->message = estrndup(err_msg, errmsg_len);
481484
}
482485
if (bson_iter_init_find(&iter, bson, "errInfo") && BSON_ITER_HOLDS_DOCUMENT(&iter)) {
483486
uint32_t len;
@@ -515,7 +518,10 @@ zend_bool phongo_writeerror_init(zval *return_value, bson_t *bson TSRMLS_DC) /*
515518
writeerror->code = bson_iter_int32(&iter);
516519
}
517520
if (bson_iter_init_find(&iter, bson, "errmsg") && BSON_ITER_HOLDS_UTF8(&iter)) {
518-
writeerror->message = bson_iter_dup_utf8(&iter, NULL);
521+
uint32_t errmsg_len;
522+
const char *err_msg = bson_iter_utf8(&iter, &errmsg_len);
523+
524+
writeerror->message = estrndup(err_msg, errmsg_len);
519525
}
520526
if (bson_iter_init_find(&iter, bson, "errInfo")) {
521527
bson_t info;

0 commit comments

Comments
 (0)