Skip to content

Commit d5c8a12

Browse files
committed
Merge pull request #63
2 parents faa8e05 + d2cd751 commit d5c8a12

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/bson.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ PHP_FUNCTION(fromJSON)
11031103

11041104
if (bson_init_from_json(&b, (const char *)data, data_len, &error)) {
11051105
RETVAL_STRINGL((const char *) bson_get_data(&b), b.len, 1);
1106+
bson_destroy(&b);
11061107
} else {
11071108
RETURN_NULL();
11081109
}

tests/bson/bug0341.phpt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--TEST--
2+
PHPC-341: fromJSON() leaks when JSON contains array or object fields
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$tests = array(
10+
'{ "foo": "yes", "bar" : false }',
11+
'{ "foo": "no", "array" : [ 5, 6 ] }',
12+
'{ "foo": "no", "obj" : { "embedded" : 3.14 } }',
13+
);
14+
15+
foreach ($tests as $test) {
16+
$bson = fromJSON($test);
17+
var_dump(toPHP($bson));
18+
}
19+
20+
?>
21+
===DONE===
22+
<?php exit(0); ?>
23+
--EXPECTF--
24+
object(stdClass)#%d (2) {
25+
["foo"]=>
26+
string(3) "yes"
27+
["bar"]=>
28+
bool(false)
29+
}
30+
object(stdClass)#%d (2) {
31+
["foo"]=>
32+
string(2) "no"
33+
["array"]=>
34+
array(2) {
35+
[0]=>
36+
int(5)
37+
[1]=>
38+
int(6)
39+
}
40+
}
41+
object(stdClass)#%d (2) {
42+
["foo"]=>
43+
string(2) "no"
44+
["obj"]=>
45+
object(stdClass)#%d (1) {
46+
["embedded"]=>
47+
float(3.14)
48+
}
49+
}
50+
===DONE===

0 commit comments

Comments
 (0)