1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:27:44 +00:00

Userland: Use allocation-failure safe functions where it's easy

I went through all callers of adopt_own() and replaced them with
try_make<>() if possible or adopt_nonnull_own_or_enomem() else
in cases where it was easy (i.e. in functions already returning
ErrorOr).

No intended behavior change.
This commit is contained in:
Nico Weber 2023-02-10 20:53:39 -05:00 committed by Jelle Raaijmakers
parent f698585097
commit 9cfd7a299c
4 changed files with 7 additions and 7 deletions

View file

@ -24,7 +24,7 @@ ErrorOr<NonnullOwnPtr<ProjectConfig>> ProjectConfig::try_load_project_config(Dep
if (!json.is_object()) if (!json.is_object())
return Error::from_string_literal("The topmost JSON element is not an object"); return Error::from_string_literal("The topmost JSON element is not an object");
return adopt_own(*new ProjectConfig(json.as_object())); return try_make<ProjectConfig>(json.as_object());
} }
NonnullOwnPtr<ProjectConfig> ProjectConfig::create_empty() NonnullOwnPtr<ProjectConfig> ProjectConfig::create_empty()

View file

@ -334,13 +334,13 @@ ErrorOr<NonnullOwnPtr<Profile>> Profile::load_from_perfcore_file(StringView path
.executable = executable, .executable = executable,
}; };
auto sampled_process = adopt_own(*new Process { auto sampled_process = TRY(adopt_nonnull_own_or_enomem(new (nothrow) Process {
.pid = event.pid, .pid = event.pid,
.executable = executable, .executable = executable,
.basename = LexicalPath::basename(executable), .basename = LexicalPath::basename(executable),
.start_valid = event.serial, .start_valid = event.serial,
.end_valid = {}, .end_valid = {},
}); }));
current_processes.set(sampled_process->pid, sampled_process); current_processes.set(sampled_process->pid, sampled_process);
all_processes.append(move(sampled_process)); all_processes.append(move(sampled_process));
@ -356,13 +356,13 @@ ErrorOr<NonnullOwnPtr<Profile>> Profile::load_from_perfcore_file(StringView path
current_processes.remove(event.pid); current_processes.remove(event.pid);
auto sampled_process = adopt_own(*new Process { auto sampled_process = TRY(adopt_nonnull_own_or_enomem(new (nothrow) Process {
.pid = event.pid, .pid = event.pid,
.executable = executable, .executable = executable,
.basename = LexicalPath::basename(executable), .basename = LexicalPath::basename(executable),
.start_valid = event.serial, .start_valid = event.serial,
.end_valid = {}, .end_valid = {},
}); }));
current_processes.set(sampled_process->pid, sampled_process); current_processes.set(sampled_process->pid, sampled_process);
all_processes.append(move(sampled_process)); all_processes.append(move(sampled_process));

View file

@ -12,7 +12,7 @@ ErrorOr<NonnullOwnPtr<ObjectFile>> Compiler::compile(Vector<String> const&)
{ {
// FIXME: implement this function // FIXME: implement this function
m_messages = {}; m_messages = {};
return adopt_own(*new ObjectFile()); return try_make<ObjectFile>();
} }
} }

View file

@ -26,7 +26,7 @@ ErrorOr<NonnullOwnPtr<LinkedShader>> Linker::link(Vector<ObjectFile const*> cons
}; };
TRY(shader.instructions.try_append(instruction)); TRY(shader.instructions.try_append(instruction));
return adopt_own(*new LinkedShader(shader)); return try_make<LinkedShader>(shader);
} }
} }