Auto-Merge pull request #2549 from octo/cid/179240
authorcollectd bot <32910397+collectd-bot@users.noreply.github.com>
Fri, 17 Nov 2017 15:32:19 +0000 (16:32 +0100)
committerGitHub <noreply@github.com>
Fri, 17 Nov 2017 15:32:19 +0000 (16:32 +0100)
Automatically merged due to "Automerge" label

src/ovs_stats.c
src/zfs_arc.c

index 20b0dd1..538386a 100644 (file)
@@ -789,7 +789,6 @@ static void ovs_stats_conn_terminate() {
  */
 static int ovs_stats_plugin_config(oconfig_item_t *ci) {
   bridge_list_t *bridge;
-  char *br_name;
 
   for (int i = 0; i < ci->children_num; i++) {
     oconfig_item_t *child = ci->children + i;
@@ -821,19 +820,22 @@ static int ovs_stats_plugin_config(oconfig_item_t *ci) {
           goto cleanup_fail;
         }
         /* get value */
-        if ((br_name = strdup(child->values[j].value.string)) == NULL) {
-          ERROR("%s: strdup() copy bridge name fail", plugin_name);
-          goto cleanup_fail;
-        }
+        char const *br_name = child->values[j].value.string;
         if ((bridge = ovs_stats_get_bridge(g_monitored_bridge_list_head,
                                            br_name)) == NULL) {
           if ((bridge = calloc(1, sizeof(bridge_list_t))) == NULL) {
             ERROR("%s: Error allocating memory for bridge", plugin_name);
             goto cleanup_fail;
           } else {
+            char *br_name_dup = strdup(br_name);
+            if (br_name_dup == NULL) {
+              ERROR("%s: strdup() copy bridge name fail", plugin_name);
+              goto cleanup_fail;
+            }
+
             pthread_mutex_lock(&g_stats_lock);
             /* store bridge name */
-            bridge->name = br_name;
+            bridge->name = br_name_dup;
             bridge->next = g_monitored_bridge_list_head;
             g_monitored_bridge_list_head = bridge;
             pthread_mutex_unlock(&g_stats_lock);
index e589184..5d37f9f 100644 (file)
@@ -208,26 +208,21 @@ static int za_read(void) {
     return -1;
   }
 
-  ksp = llist_create();
-  if (ksp == NULL) {
-    ERROR("zfs_arc plugin: `llist_create' failed.");
-    fclose(fh);
-    return -1;
-  }
-
-  // Ignore the first two lines because they contain information about
-  // the rest of the file.
-  // See kstat_seq_show_headers module/spl/spl-kstat.c of the spl kernel
-  // module.
-  if (fgets(buffer, sizeof(buffer), fh) == NULL) {
-    ERROR("zfs_arc plugin: \"%s\" does not contain a single line.",
+  /* Ignore the first two lines because they contain information about the rest
+   * of the file.
+   * See kstat_seq_show_headers module/spl/spl-kstat.c of the spl kernel module.
+   */
+  if ((fgets(buffer, sizeof(buffer), fh) == NULL) ||
+      (fgets(buffer, sizeof(buffer), fh) == NULL)) {
+    ERROR("zfs_arc plugin: \"%s\" does not contain at least two lines.",
           ZOL_ARCSTATS_FILE);
     fclose(fh);
     return -1;
   }
-  if (fgets(buffer, sizeof(buffer), fh) == NULL) {
-    ERROR("zfs_arc plugin: \"%s\" does not contain at least two lines.",
-          ZOL_ARCSTATS_FILE);
+
+  ksp = llist_create();
+  if (ksp == NULL) {
+    ERROR("zfs_arc plugin: `llist_create' failed.");
     fclose(fh);
     return -1;
   }