diff --git a/pressure-vessel/launcher.c b/pressure-vessel/launcher.c index 146fb1300c85df20a3e1c2b57011af7d96589e39..3c2d020346b0830bfa293e9eed37b4fbaff021c2 100644 --- a/pressure-vessel/launcher.c +++ b/pressure-vessel/launcher.c @@ -60,7 +60,6 @@ typedef GDBusServer AutoDBusServer; G_DEFINE_AUTOPTR_CLEANUP_FUNC(AutoDBusServer, g_object_unref) static PvPortalListener *global_listener; -static const char * const *global_original_environ = NULL; static FILE *original_stdout = NULL; static FILE *info_fh = NULL; static GHashTable *lock_env_hash = NULL; @@ -69,7 +68,6 @@ static GHashTable *client_pid_data_hash = NULL; static guint name_owner_id = 0; static GMainLoop *main_loop; static PvLauncher1 *launcher; -static gchar *original_cwd_l = NULL; /* * Close the --info-fd, and also close standard output (if different). @@ -376,7 +374,7 @@ handle_launch (PvLauncher1 *object, } else { - env = g_strdupv ((gchar **) global_original_environ); + env = g_strdupv (global_listener->original_environ); } n_envs = g_variant_n_children (arg_envs); @@ -425,7 +423,8 @@ handle_launch (PvLauncher1 *object, } if (arg_cwd_path == NULL) - env = g_environ_setenv (env, "PWD", original_cwd_l, TRUE); + env = g_environ_setenv (env, "PWD", global_listener->original_cwd_l, + TRUE); else env = g_environ_setenv (env, "PWD", arg_cwd_path, TRUE); @@ -1109,7 +1108,6 @@ int main (int argc, char *argv[]) { - g_auto(GStrv) original_environ = NULL; g_autoptr(AutoDBusServer) server = NULL; g_autoptr(GOptionContext) context = NULL; guint signals_id = 0; @@ -1122,9 +1120,6 @@ main (int argc, my_pid = getpid (); global_listener = pv_portal_listener_new (); - original_environ = g_get_environ (); - global_original_environ = (const char * const *) original_environ; - pv_get_current_dirs (NULL, &original_cwd_l); setlocale (LC_ALL, ""); @@ -1447,9 +1442,6 @@ out: g_clear_error (&local_error); close_info_fh (); - g_free (original_cwd_l); - global_original_environ = NULL; - g_debug ("Exiting with status %d", ret); return ret; } diff --git a/pressure-vessel/portal-listener.c b/pressure-vessel/portal-listener.c index 3f9786fbe8835ff0d57a74c79de174e66098ccfa..3a17e1058194966bd2923e608578e8dca5c09d81 100644 --- a/pressure-vessel/portal-listener.c +++ b/pressure-vessel/portal-listener.c @@ -27,7 +27,12 @@ #include "config.h" #include "subprojects/libglnx/config.h" +#include "steam-runtime-tools/glib-backports-internal.h" +#include "steam-runtime-tools/utils-internal.h" +#include "libglnx/libglnx.h" + #include "portal-listener.h" +#include "utils.h" struct _PvPortalListenerClass { @@ -39,6 +44,8 @@ G_DEFINE_TYPE (PvPortalListener, pv_portal_listener, G_TYPE_OBJECT) void pv_portal_listener_init (PvPortalListener *self) { + self->original_environ = g_get_environ (); + pv_get_current_dirs (NULL, &self->original_cwd_l); } static void @@ -56,7 +63,8 @@ pv_portal_listener_finalize (GObject *object) { PvPortalListener *self = PV_PORTAL_LISTENER (object); - (void) self; + g_clear_pointer (&self->original_environ, g_strfreev); + g_clear_pointer (&self->original_cwd_l, g_free); G_OBJECT_CLASS (pv_portal_listener_parent_class)->finalize (object); } diff --git a/pressure-vessel/portal-listener.h b/pressure-vessel/portal-listener.h index 4be8bbe1cd68ed9033806d529d1d30342ec5d5cc..4c435b0cdf9c17ee0643352c1dafbae3555d09f6 100644 --- a/pressure-vessel/portal-listener.h +++ b/pressure-vessel/portal-listener.h @@ -50,6 +50,8 @@ GType pv_portal_listener_get_type (void); struct _PvPortalListener { GObject parent; + GStrv original_environ; + gchar *original_cwd_l; }; PvPortalListener *pv_portal_listener_new (void);