From 0334ea1c889331adb02d361670e24b3f85b5b0d6 Mon Sep 17 00:00:00 2001 From: Antoine Jacoutot Date: Mon, 13 May 2019 20:47:46 +0200 Subject: [PATCH] pid_get_parent: fix for OpenBSD This fixes a long standing bug in pid_get_parent on OpenBSD (which was mine so... my fault). kp wasn't properly allocated and the function could return random failures. --- gtk/gtkmountoperation-x11.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gtk/gtkmountoperation-x11.c b/gtk/gtkmountoperation-x11.c index 345570c301..1b7bff6aa1 100644 --- a/gtk/gtkmountoperation-x11.c +++ b/gtk/gtkmountoperation-x11.c @@ -736,7 +736,7 @@ pid_get_command_line (GPid pid) static GPid pid_get_parent (GPid pid) { - struct kinfo_proc kp; + struct kinfo_proc *kp; size_t len; GPid ppid; @@ -747,11 +747,14 @@ pid_get_parent (GPid pid) return (-1); mib[5] = (len / sizeof(struct kinfo_proc)); - if (sysctl (mib, G_N_ELEMENTS (mib), &kp, &len, NULL, 0) < 0) + kp = g_malloc0 (len); + + if (sysctl (mib, G_N_ELEMENTS (mib), kp, &len, NULL, 0) < 0) return -1; - ppid = kp.p_ppid; + ppid = kp->p_ppid; + g_free (kp); return ppid; }