Commit f333dfc
committed
repo: catch exceptions when iterating through status
When we call the block, an exception or even a call to `break` would cause us to
unwind the stack and skip any resource freeing that we may have. The solution is
to call `rb_protect` which will let us catch the exception and raise whenever we
need to.
Doing this as part of a `git_status_foreach` is unnecessarily awkward so move to
iterating over the status list ourselves and free the entry list as soon as we
notice there was an exception.
For example, this program will consume memory
indefinitely:
require 'rugged'
repo = Rugged::Repository.new ARGV[0]
loop do
repo.status do |file, status_data|
break
end
end
Thanks to Aaron Patterson for discovering this and the original hacky fix.1 parent 2e2e1ea commit f333dfc
2 files changed
+46
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1502 | 1502 | | |
1503 | 1503 | | |
1504 | 1504 | | |
1505 | | - | |
1506 | | - | |
1507 | | - | |
1508 | | - | |
1509 | | - | |
1510 | | - | |
1511 | | - | |
1512 | | - | |
1513 | | - | |
1514 | 1505 | | |
1515 | 1506 | | |
1516 | 1507 | | |
| |||
1527 | 1518 | | |
1528 | 1519 | | |
1529 | 1520 | | |
1530 | | - | |
| 1521 | + | |
| 1522 | + | |
1531 | 1523 | | |
| 1524 | + | |
1532 | 1525 | | |
1533 | 1526 | | |
1534 | 1527 | | |
| |||
1537 | 1530 | | |
1538 | 1531 | | |
1539 | 1532 | | |
1540 | | - | |
1541 | | - | |
1542 | | - | |
1543 | | - | |
1544 | | - | |
1545 | | - | |
| 1533 | + | |
1546 | 1534 | | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
1547 | 1557 | | |
1548 | 1558 | | |
1549 | 1559 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
36 | 56 | | |
37 | 57 | | |
38 | 58 | | |
| |||
0 commit comments