Merge branch 'collectd-4.3'
[collectd.git] / src / utils_cmd_getval.c
index 85028d0..f110196 100644 (file)
@@ -35,6 +35,8 @@ int handle_getval (FILE *fh, char **fields, int fields_num)
   gauge_t *values;
   size_t values_num;
 
+  char *identifier_copy;
+
   const data_set_t *ds;
 
   int   status;
@@ -57,7 +59,11 @@ int handle_getval (FILE *fh, char **fields, int fields_num)
     return (-1);
   }
 
-  status = parse_identifier (fields[1], &hostname,
+  /* parse_identifier() modifies its first argument,
+   * returning pointers into it */
+  identifier_copy = sstrdup (fields[1]);
+
+  status = parse_identifier (identifier_copy, &hostname,
       &plugin, &plugin_instance,
       &type, &type_instance);
   if (status != 0)
@@ -65,6 +71,7 @@ int handle_getval (FILE *fh, char **fields, int fields_num)
     DEBUG ("unixsock plugin: Cannot parse `%s'", fields[1]);
     fprintf (fh, "-1 Cannot parse identifier.\n");
     fflush (fh);
+    sfree (identifier_copy);
     return (-1);
   }
 
@@ -74,6 +81,7 @@ int handle_getval (FILE *fh, char **fields, int fields_num)
     DEBUG ("unixsock plugin: plugin_get_ds (%s) == NULL;", type);
     fprintf (fh, "-1 Type `%s' is unknown.\n", type);
     fflush (fh);
+    sfree (identifier_copy);
     return (-1);
   }
 
@@ -84,6 +92,7 @@ int handle_getval (FILE *fh, char **fields, int fields_num)
   {
     fprintf (fh, "-1 No such value\n");
     fflush (fh);
+    sfree (identifier_copy);
     return (-1);
   }
 
@@ -95,6 +104,7 @@ int handle_getval (FILE *fh, char **fields, int fields_num)
     fprintf (fh, "-1 Error reading value from cache.\n");
     fflush (fh);
     sfree (values);
+    sfree (identifier_copy);
     return (-1);
   }
 
@@ -111,6 +121,7 @@ int handle_getval (FILE *fh, char **fields, int fields_num)
   fflush (fh);
 
   sfree (values);
+  sfree (identifier_copy);
 
   return (0);
 } /* int handle_getval */