Commit d6fc2cd
committed
fix: destroy C++ locals before raising a Lua error
`luaL_error` and `lua_error` report a failure by longjmp-ing to the
enclosing `lua_pcall`. The jump runs no C++ destructors on the frames
it unwinds, so any local with a non-trivial destructor still alive at
the point of the raise is leaked, and the unwind itself is undefined.
Two of the Lua binding functions raised while such a local was live.
The one invoked when a script assigns to a `dom::Object` field held
the value being assigned and raised from inside a `catch`. The one
invoked when a script calls a `dom::Function` held the argument
`dom::Array`, the call result, and the function being invoked.
Stage the outcome on the Lua stack first - push the result value, or
build a location-prefixed message with `luaL_where` and `lua_concat` -
then close the scope so every C++ local is destroyed, and only then
raise. Lua copies a pushed string, so the message outlives the
destructors.1 parent 2094838 commit d6fc2cd
1 file changed
Lines changed: 43 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
598 | 598 | | |
599 | 599 | | |
600 | 600 | | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
609 | 605 | | |
610 | | - | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
611 | 620 | | |
612 | | - | |
| 621 | + | |
613 | 622 | | |
614 | 623 | | |
615 | 624 | | |
| |||
740 | 749 | | |
741 | 750 | | |
742 | 751 | | |
743 | | - | |
744 | | - | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
745 | 758 | | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | | - | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
754 | 776 | | |
755 | | - | |
756 | | - | |
| 777 | + | |
757 | 778 | | |
758 | 779 | | |
759 | 780 | | |
| |||
0 commit comments