From 58abc1fc198a8579667ea2164c33964b250a0435 Mon Sep 17 00:00:00 2001 From: Antoine Jacoutot Date: Wed, 16 Apr 2014 10:27:09 +0200 Subject: [PATCH] platform_get_argv0: drop unneeded headers for OpenBSD And properly set the size of len. There is also no need for realloc(), g_malloc0 will do just fine. https://bugzilla.gnome.org/show_bug.cgi?id=728280 --- glib/goption.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/glib/goption.c b/glib/goption.c index 31bbf164f..a11971fe9 100644 --- a/glib/goption.c +++ b/glib/goption.c @@ -185,9 +185,7 @@ #include #if defined __OpenBSD__ -#include #include -#include #include #endif @@ -1763,13 +1761,16 @@ platform_get_argv0 (void) g_free (cmdline); return base_arg0; #elif defined __OpenBSD__ - char **cmdline = NULL; + char **cmdline; char *base_arg0; - gsize len = PATH_MAX; + gsize len; int mib[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV }; - cmdline = (char **) realloc (cmdline, len); + if (sysctl (mib, G_N_ELEMENTS (mib), NULL, &len, NULL, 0) == -1) + return NULL; + + cmdline = g_malloc0 (len); if (sysctl (mib, G_N_ELEMENTS (mib), cmdline, &len, NULL, 0) == -1) {