1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 17:15:09 +00:00

Userland: Don't leak objects when constructor arguments throw

Similar to d253beb2f7.

Found with Ali's clang-query script in Shell:

```
for $(find AK Userland -type f -name '*.h' -o -name '*.cpp') {
    in_parallel -j 12 -- clang-query -p \
    Build/lagom/compile_commands.json $it -c \
    'm cxxNewExpr(has(cxxConstructExpr(hasAnyArgument(hasDescendant( \
        allOf(isExpandedFromMacro("TRY"), stmtExpr()))))))' \
    } | grep -v 'matches.' | tee results
```
This commit is contained in:
Andrew Kaster 2023-12-13 15:45:32 -07:00 committed by Andrew Kaster
parent d253beb2f7
commit c145d5410c
4 changed files with 20 additions and 11 deletions

View file

@ -420,8 +420,10 @@ ErrorOr<RefPtr<AST::Value const>> Shell::look_up_local_variable(StringView name)
ErrorOr<RefPtr<AST::Value const>> Shell::get_argument(size_t index) const
{
if (index == 0)
return adopt_ref(*new AST::StringValue(TRY(String::from_deprecated_string(current_script))));
if (index == 0) {
auto current_script_string = TRY(String::from_deprecated_string(current_script));
return adopt_ref(*new AST::StringValue(current_script_string));
}
--index;
if (auto argv = TRY(look_up_local_variable("ARGV"sv))) {