Code

sensors plugin: Fix memory leak in configuration; enhance comments.
authorFlorian Forster <octo@collectd.org>
Thu, 23 Feb 2012 09:23:27 +0000 (10:23 +0100)
committerFlorian Forster <octo@collectd.org>
Thu, 23 Feb 2012 09:23:27 +0000 (10:23 +0100)
Change-Id: Ic4f9d2aae1aec9fbd83307fe3bb7d476f49f6827

src/sensors.c

index 96a54fca91cb56bc9bb825f93a749b291c2c71c7..7c1566c3022d9db096231d31fd3b5a7ee219041e 100644 (file)
@@ -227,12 +227,17 @@ static int sensors_config (const char *key, const char *value)
        if (sensor_list == NULL)
                sensor_list = ignorelist_create (1);
 
+       /* TODO: This setting exists for compatibility with old versions of
+        * lm-sensors. Remove support for those ancient versions in the next
+        * major release. */
        if (strcasecmp (key, "SensorConfigFile") == 0)
        {
-               /* we will leak memory here if SensorConfigFile is
-                  used more than once, maybe we can just drop support
-                  for broken, extremely ancient libsensors? */
-               conffile = strdup (value);
+               char *tmp = strdup (value);
+               if (tmp != NULL)
+               {
+                       sfree (conffile);
+                       conffile = tmp;
+               }
        }
        else if (strcasecmp (key, "Sensor") == 0)
        {