From f4e0ca6bb59e633618ff3918fde47018672ea758 Mon Sep 17 00:00:00 2001 From: Sean Campbell Date: Wed, 11 Oct 2017 17:50:56 -0400 Subject: [PATCH] Make g_strings in perl.c not global so that hostname_g as a char* doesn't break it.x --- src/daemon/globals.c | 18 +++++++++--------- src/perl.c | 11 +++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/daemon/globals.c b/src/daemon/globals.c index 2222a5ce..9b0aec73 100644 --- a/src/daemon/globals.c +++ b/src/daemon/globals.c @@ -28,15 +28,6 @@ #include #endif -void hostname_set(char const *hostname) { - char *h = strdup(hostname); - if (h == NULL) - return; - - free(hostname_g); - hostname_g = h; -} - /* * Global variables */ @@ -47,3 +38,12 @@ int timeout_g; kstat_ctl_t *kc; #endif +void hostname_set(char const *hostname) { + char *h = strdup(hostname); + if (h == NULL) + return; + + free(hostname_g); + hostname_g = h; +} + diff --git a/src/perl.c b/src/perl.c index d2a00bfd..9268086f 100644 --- a/src/perl.c +++ b/src/perl.c @@ -261,12 +261,6 @@ struct { {"Collectd::NOTIF_WARNING", NOTIF_WARNING}, {"Collectd::NOTIF_OKAY", NOTIF_OKAY}, {"", 0}}; - -struct { - char name[64]; - char *var; -} g_strings[] = {{"Collectd::hostname_g", hostname_g}, {"", NULL}}; - /* * Helper functions for data type conversion. */ @@ -2390,6 +2384,11 @@ static void xs_init(pTHX) { * accessing any such variable (this is basically the same as using * tie() in Perl) */ /* global strings */ + struct { + char name[64]; + char *var; + } g_strings[] = {{"Collectd::hostname_g", hostname_g}, {"", NULL}}; + for (int i = 0; '\0' != g_strings[i].name[0]; ++i) { tmp = get_sv(g_strings[i].name, 1); sv_magicext(tmp, NULL, PERL_MAGIC_ext, &g_pv_vtbl, g_strings[i].var, 0); -- 2.30.2