From 77fc980fe2afeaf8be2a6dc4ccf82cf63397f5bf Mon Sep 17 00:00:00 2001 From: Neil Mckee Date: Thu, 15 Dec 2016 14:59:43 -0800 Subject: [PATCH] Fix memory leak in mod_systemd --- hsflowd.spec | 2 +- src/Linux/mod_systemd.c | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/hsflowd.spec b/hsflowd.spec index 9412d215..a7974c32 100644 --- a/hsflowd.spec +++ b/hsflowd.spec @@ -1,7 +1,7 @@ Summary: host sFlow daemon Name: hsflowd Version: 2.0.7 -Release: 3 +Release: 4 License: http://sflow.net/license.html Group: Applications/Internet URL: http://sflow.net diff --git a/src/Linux/mod_systemd.c b/src/Linux/mod_systemd.c index 5c70f1af..898615d2 100644 --- a/src/Linux/mod_systemd.c +++ b/src/Linux/mod_systemd.c @@ -184,6 +184,10 @@ extern "C" { container = (HSPVMState_SYSTEMD *)getVM(mod, unit->uuid, YES, sizeof(HSPVMState_SYSTEMD), VMTYPE_SYSTEMD, agentCB_getCounters_SYSTEMD_request); assert(container != NULL); if(container) { + if(container->id) { + my_free(container->id); + container->id = NULL; + } container->id = my_strdup(unit->name); // add to collections UTHashAdd(mdata->vmsByID, container); @@ -904,7 +908,15 @@ extern "C" { && my_strlen(val.str) && regexec(mdata->system_slice_regex, val.str, 0, NULL, 0) == 0) { myDebug(1, "UNIT CGROUP[cgroup=\"%s\"]", val.str); - unit->cgroup = my_strdup(val.str); + if(unit->cgroup + && !my_strequal(unit->cgroup, val.str)) { + // cgroup name changed + my_free(unit->cgroup); + unit->cgroup = NULL; + } + if(!unit->cgroup) + unit->cgroup = my_strdup(val.str); + // read the process ids // mark and sweep - mark @@ -970,7 +982,15 @@ extern "C" { DBusBasicValue val; if(db_get(&it, DBUS_TYPE_OBJECT_PATH, &val) && val.str) { - unit->obj = my_strdup(val.str); + if(unit->obj + && !my_strequal(unit->obj, val.str)) { + // obj changed + my_free(unit->obj); + unit->obj = NULL; + } + if(!unit->obj) + unit->obj = my_strdup(val.str); + myDebug(1, "UNIT OBJ[obj=\"%s\"]", val.str); dbusMethod(mod, handler_controlGroup,