Skip to content

Commit

Permalink
Do not allocate memory between fork() and exec() (#3588)
Browse files Browse the repository at this point in the history
Fixes: #3581
  • Loading branch information
mattkae authored and AlanGriffiths committed Sep 9, 2024
1 parent 13cc41e commit 7e21a55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/miral/launch_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace
{
void strip_mir_env_variables()
auto mir_env_variables() -> std::vector<std::string>
{
static char const mir_prefix[] = "MIR_";

Expand All @@ -51,10 +51,7 @@ void strip_mir_env_variables()
}
}

for (auto const& var : vars_to_remove)
{
unsetenv(var.c_str());
}
return vars_to_remove;
}
} // namespace

Expand All @@ -64,6 +61,8 @@ auto miral::launch_app_env(
mir::optional_value<std::string> const& x11_display,
miral::AppEnvironment const& app_env) -> pid_t
{
static auto const vars_to_remove = mir_env_variables();

pid_t pid = fork();

if (pid < 0)
Expand All @@ -73,7 +72,10 @@ auto miral::launch_app_env(

if (pid == 0)
{
strip_mir_env_variables();
for (auto const& var : vars_to_remove)
{
unsetenv(var.c_str());
}

if (x11_display)
{
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/wayland/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct wl_shm_pool* make_shm_pool(struct wl_shm* shm, int size, void **data)
static auto const template_filename =
std::string{getenv("XDG_RUNTIME_DIR")} + "/wayland-cursor-shared-XXXXXX";

auto const filename = strdup(template_filename.c_str());
char* const filename = const_cast<char*>(template_filename.c_str());
mir::Fd const fd{mkostemp(filename, O_CLOEXEC)};
unlink(filename);
free(filename);
Expand Down

0 comments on commit 7e21a55

Please sign in to comment.