Adding our standard mutex for protecting cfs_status from multiple
conflicting changes solves two things. First, it now protects
cfs_status as it was changed here and secondly, it protects the
global rrd_dump_buf and rrd_dump_last helper variables from
incosistent access and a double free chance.
Fixes: #1559
Reported-by: Tobias Böhm <tb@robhost.de>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
cfs_rrd_dump(GString *str)
{
time_t ctime;
cfs_rrd_dump(GString *str)
{
time_t ctime;
+ g_mutex_lock (&mutex);
+
+ time(&ctime);
if (rrd_dump_buf && (ctime - rrd_dump_last) < 2) {
g_string_assign(str, rrd_dump_buf);
if (rrd_dump_buf && (ctime - rrd_dump_last) < 2) {
g_string_assign(str, rrd_dump_buf);
+ g_mutex_unlock (&mutex);
if (rrd_dump_buf)
g_free(rrd_dump_buf);
rrd_dump_buf = g_strdup(str->str);
if (rrd_dump_buf)
g_free(rrd_dump_buf);
rrd_dump_buf = g_strdup(str->str);
+
+ g_mutex_unlock (&mutex);