mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:38:11 +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:
parent
d253beb2f7
commit
c145d5410c
4 changed files with 20 additions and 11 deletions
|
@ -45,13 +45,15 @@ static constexpr LoaderPluginInitializer s_initializers[] = {
|
|||
ErrorOr<NonnullRefPtr<Loader>, LoaderError> Loader::create(StringView path)
|
||||
{
|
||||
auto stream = TRY(Core::MappedFile::map(path, Core::MappedFile::Mode::ReadOnly));
|
||||
return adopt_ref(*new (nothrow) Loader(TRY(Loader::create_plugin(move(stream)))));
|
||||
auto plugin = TRY(Loader::create_plugin(move(stream)));
|
||||
return adopt_ref(*new (nothrow) Loader(move(plugin)));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Loader>, LoaderError> Loader::create(ReadonlyBytes buffer)
|
||||
{
|
||||
auto stream = TRY(try_make<FixedMemoryStream>(buffer));
|
||||
return adopt_ref(*new (nothrow) Loader(TRY(Loader::create_plugin(move(stream)))));
|
||||
auto plugin = TRY(Loader::create_plugin(move(stream)));
|
||||
return adopt_ref(*new (nothrow) Loader(move(plugin)));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<LoaderPlugin>, LoaderError> Loader::create_plugin(NonnullOwnPtr<SeekableStream> stream)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue