Skip to content

Commit

Permalink
Fix: set reference to static
Browse files Browse the repository at this point in the history
Sets reference in logging.c to static to prevent wrongful compiler
optimizations on initialization.

This is an attempt to fix: greenbone/gsad#115

(cherry picked from commit 573ec74)
  • Loading branch information
nichtsfrei authored and Kraemii committed Feb 9, 2023
1 parent 6c335b4 commit a97a53a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions base/logging.c
Expand Up @@ -389,7 +389,7 @@ gvm_log_unlock (void)
g_mutex_unlock (logger_mutex);
}

char *reference = NULL;
static char *reference = NULL;

/**
* @brief Set the log reference object.
Expand All @@ -407,7 +407,8 @@ char *reference = NULL;
void
set_log_reference (char *ref)
{
g_free (reference);
if (reference)
g_free ((char *) reference);
reference = ref;
}

Expand All @@ -422,7 +423,7 @@ set_log_reference (char *ref)
char *
get_log_reference (void)
{
return reference;
return (char *) reference;
}

/**
Expand All @@ -434,7 +435,8 @@ get_log_reference (void)
void
free_log_reference (void)
{
g_free (reference);
if (reference)
g_free ((char *) reference);
reference = NULL;
}

Expand Down Expand Up @@ -579,7 +581,7 @@ gvm_log_func (const char *log_domain, GLogLevelFlags log_level,
/* If the current char is a % and the next one is a p, get the pid. */
if ((*tmp == '%') && (*(tmp + 1) == 'p'))
{
if (reference)
if (reference != NULL)
{
prepend_tmp =
g_strdup_printf ("%s%d%s%s", prepend_buf, (int) getpid (),
Expand Down

0 comments on commit a97a53a

Please sign in to comment.