Skip to content

Commit

Permalink
Merge pull request #1326 from truenas/NAS-126029
Browse files Browse the repository at this point in the history
NAS-126029 / 13.1 / Collectd memory leak fix
  • Loading branch information
yocalebo authored Feb 21, 2024
2 parents 177b6a8 + 5769e36 commit 0778977
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion net-mgmt/collectd5/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

PORTNAME= collectd
PORTVERSION= 5.11.0
PORTREVISION= 7
PORTREVISION= 8
CATEGORIES= net-mgmt
MASTER_SITES= https://storage.googleapis.com/collectd-tarballs/
PKGNAMESUFFIX= 5
Expand Down
52 changes: 32 additions & 20 deletions net-mgmt/collectd5/files/patch-src__ctl.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- src/ctl.c.orig 2022-01-21 13:11:05 UTC
+++ src/ctl.c
@@ -0,0 +1,418 @@
--- src/ctl.c.orig 1970-01-01 01:00:00.000000000 +0100
+++ src/ctl.c 2023-12-19 07:10:28.254423826 +0100
@@ -0,0 +1,430 @@
+/**
+ * collectd - src/ctl.c
+ *
Expand Down Expand Up @@ -134,6 +134,22 @@
+} *agrs;
+static int nagrs;
+
+static void ctl_clean()
+{
+ int i;
+
+ for (i = 0; i < maxports; i++) {
+ free(ports[i].name);
+ ports[i].name = NULL;
+ free(ports[i].ppvp);
+ ports[i].ppvp = NULL;
+ ports[i].ha = 0;
+ ports[i].agr = 0;
+ free(agrs[i].name);
+ agrs[i].name = NULL;
+ }
+}
+
+static int ctl_init(void)
+{
+
Expand Down Expand Up @@ -162,7 +178,8 @@
+
+static int ctl_shutdown(void)
+{
+
+ if (portbuf) free(portbuf);
+ ctl_clean();
+ free(statbuf);
+ free(ports);
+ free(agrs);
Expand Down Expand Up @@ -236,21 +253,12 @@
+ return (-1);
+ }
+
+ for (i = 0; i < maxports; i++) {
+ free(ports[i].name);
+ ports[i].name = NULL;
+ free(ports[i].ppvp);
+ ports[i].ppvp = NULL;
+ ports[i].ha = 0;
+ ports[i].agr = 0;
+ free(agrs[i].name);
+ agrs[i].name = NULL;
+ }
+ ctl_clean();
+ nagrs = 0;
+
+ for (i = 0; i < xpath_obj->nodesetval->nodeNr; ++i) {
+ xmlNodePtr portnode, child;
+ char *id, *name, *pp, *vp, *type;
+ char *id, *name, *pp, *vp, *type, *online;
+ int pid;
+
+ portnode = xpath_obj->nodesetval->nodeTab[i];
Expand All @@ -259,7 +267,7 @@
+ if (!id) continue;
+ pid = atoi(id);
+ xmlFree (id);
+ name = pp = vp = type = NULL;
+ name = pp = vp = type = online = NULL;
+ child = portnode->xmlChildrenNode;
+ while (child != NULL) {
+ if ((!xmlStrcmp(child->name,
Expand All @@ -280,14 +288,14 @@
+ child->xmlChildrenNode, 1);
+ } else if ((!xmlStrcmp(child->name,
+ (const xmlChar *)"online"))) {
+ if (xmlStrcmp(xmlNodeListGetString (xml_doc,
+ child->xmlChildrenNode, 1),
+ (const xmlChar *)"YES") != 0)
+ online = (char *) xmlNodeListGetString (xml_doc,
+ child->xmlChildrenNode, 1);
+ if (xmlStrcmp((const xmlChar *) online, (const xmlChar *)"YES") != 0)
+ goto next;
+ }
+ child = child->next;
+ }
+ if (!name || !pp || !vp)
+ if (!name || !pp || !vp || !type)
+ goto next;
+
+ ports[pid].name = strdup(name);
Expand All @@ -307,6 +315,10 @@
+
+next:
+ if (name) xmlFree (name);
+ if (pp) xmlFree(pp);
+ if (vp) xmlFree(vp);
+ if (type) xmlFree(type);
+ if (online) xmlFree(online);
+ }
+
+ xmlXPathFreeObject(xpath_obj);
Expand Down

0 comments on commit 0778977

Please sign in to comment.