Skip to content

Commit

Permalink
Fix memory leak in mod_systemd
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Mckee authored and Neil Mckee committed Dec 15, 2016
1 parent e47b040 commit 77fc980
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hsflowd.spec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 22 additions & 2 deletions src/Linux/mod_systemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 77fc980

Please sign in to comment.