action: Drop unneeded allocations 23/214723/6
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 25 Sep 2019 13:05:27 +0000 (15:05 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 26 Sep 2019 11:42:59 +0000 (13:42 +0200)
Change-Id: Iae5e6c5757c9e96a24ae5e7c5923c349b185faad

Makefile
src/action.c

index daf98fb..cfaf793 100644 (file)
--- 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)`
index a3bc6e5..e3f0f80 100644 (file)
@@ -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;
 }