From f5f09e4ac06e72dffefd76b80fab5aa901d9da6b Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Wed, 25 Sep 2019 15:05:27 +0200 Subject: [PATCH] action: Drop unneeded allocations Change-Id: Iae5e6c5757c9e96a24ae5e7c5923c349b185faad --- Makefile | 1 + src/action.c | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index daf98fb..cfaf793 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ CFLAGS = \ -I$(srcdir) \ `pkg-config --cflags $(libs)` \ -DKMOD_PATH=\"$(KMOD_PATH)\" \ + -D_GNU_SOURCE \ -fPIE LDFLAGS = `pkg-config --libs $(libs)` diff --git a/src/action.c b/src/action.c index a3bc6e5..e3f0f80 100644 --- a/src/action.c +++ b/src/action.c @@ -172,14 +172,11 @@ static GPid spawn_crash_manager(struct action_data *ad) { GPid child_pid = 0; GError *error = NULL; - gchar **argv; + char *pid_str = NULL; + if (asprintf(&pid_str, "%d", ad->ds->process->pid) == -1) + goto out; - argv = g_new(gchar *, 5); - argv[0] = g_strdup(CRASH_MANAGER_BIN); - argv[1] = g_strdup_printf("-p%d", ad->ds->process->pid); - argv[2] = g_strdup("-l"); - argv[3] = g_strdup("-r"); - argv[4] = NULL; + char *argv[] = {CRASH_MANAGER_BIN, "-lrp", pid_str, NULL}; _D_PROC(ad->ds->process, "Generating report..."); @@ -191,9 +188,10 @@ static GPid spawn_crash_manager(struct action_data *ad) _E("Unable to spawn child process: %s", error->message); g_error_free(error); } + _D("Spawned child process pid %d", child_pid); - g_strfreev(argv); - +out: + free(pid_str); return child_pid; } -- 2.34.1