Commit 9b7b648
committed
Fix memory leak when exception is raised during JSON generation part 2
Commit 44df509 fixed it for StandardError, but other exceptions and
jumps are also possible. Use rb_ensure() to release FBuffer instead of
rb_rescue().
A reproducer:
o = Object.new
def o.to_json(a) = throw :a
a = ["make heap allocation"*100, o]
10.times do
100_000.times do
catch(:a) { JSON(a) }
end
puts `ps -o rss= -p #{$$}`
end1 parent 5f43f9f commit 9b7b648
2 files changed
+6
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | | - | |
287 | 286 | | |
288 | 287 | | |
289 | 288 | | |
290 | | - | |
291 | | - | |
292 | | - | |
| 289 | + | |
293 | 290 | | |
294 | 291 | | |
295 | 292 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1444 | 1444 | | |
1445 | 1445 | | |
1446 | 1446 | | |
1447 | | - | |
| 1447 | + | |
1448 | 1448 | | |
1449 | 1449 | | |
1450 | | - | |
| 1450 | + | |
1451 | 1451 | | |
1452 | 1452 | | |
1453 | 1453 | | |
1454 | 1454 | | |
1455 | | - | |
1456 | | - | |
1457 | 1455 | | |
1458 | 1456 | | |
1459 | 1457 | | |
| |||
1474 | 1472 | | |
1475 | 1473 | | |
1476 | 1474 | | |
1477 | | - | |
1478 | | - | |
1479 | | - | |
| 1475 | + | |
1480 | 1476 | | |
1481 | 1477 | | |
1482 | 1478 | | |
| |||
1522 | 1518 | | |
1523 | 1519 | | |
1524 | 1520 | | |
1525 | | - | |
1526 | | - | |
1527 | | - | |
| 1521 | + | |
1528 | 1522 | | |
1529 | 1523 | | |
1530 | 1524 | | |
| |||
2030 | 2024 | | |
2031 | 2025 | | |
2032 | 2026 | | |
2033 | | - | |
2034 | | - | |
2035 | | - | |
| 2027 | + | |
2036 | 2028 | | |
2037 | 2029 | | |
2038 | 2030 | | |
| |||
0 commit comments