From 864371bb8ac5b734b850700813b55f35b768d18d Mon Sep 17 00:00:00 2001 From: Alan Griffiths Date: Thu, 5 Sep 2024 17:41:07 +0100 Subject: [PATCH 1/2] Fix random leak --- src/platforms/wayland/cursor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/wayland/cursor.cpp b/src/platforms/wayland/cursor.cpp index 1c0d589d1c5..e4eda7d8f0f 100644 --- a/src/platforms/wayland/cursor.cpp +++ b/src/platforms/wayland/cursor.cpp @@ -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(template_filename.c_str()); mir::Fd const fd{mkostemp(filename, O_CLOEXEC)}; unlink(filename); free(filename); From 0d39af8667b6c09cf15321c9f4d8377e799d4d3f Mon Sep 17 00:00:00 2001 From: Alan Griffiths Date: Thu, 5 Sep 2024 17:46:42 +0100 Subject: [PATCH 2/2] Allocate memory before fork() --- src/miral/launch_app.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/miral/launch_app.cpp b/src/miral/launch_app.cpp index bb028aff67a..0087b08e879 100644 --- a/src/miral/launch_app.cpp +++ b/src/miral/launch_app.cpp @@ -29,7 +29,7 @@ namespace { -void strip_mir_env_variables() +auto mir_env_variables() -> std::vector { static char const mir_prefix[] = "MIR_"; @@ -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 @@ -64,6 +61,8 @@ auto miral::launch_app_env( mir::optional_value 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) @@ -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) {