Merge branch 'collectd-5.4' into collectd-5.5
[collectd.git] / src / openvpn.c
index 6d89b37..a36de9d 100644 (file)
@@ -189,8 +189,6 @@ static int single_read (char *name, FILE *fh)
        post_compress = 0;
        pre_decompress = 0;
        post_decompress = 0;
-       overhead_rx = 0;
-       overhead_tx = 0;
 
        while (fgets (buffer, sizeof (buffer), fh) != NULL)
        {
@@ -267,7 +265,7 @@ static int multi1_read (char *name, FILE *fh)
 {
        char buffer[1024];
        char *fields[10];
-       int  fields_num, read = 0, found_header = 0;
+       int  fields_num, found_header = 0;
        long long sum_users = 0;
 
        /* read the file until the "ROUTING TABLE" line is found (no more info after) */
@@ -314,17 +312,15 @@ static int multi1_read (char *name, FILE *fh)
                                                atoll (fields[3])); /* "Bytes Sent" */
                        }
                }
-
-               read = 1;
        }
 
+       if (ferror (fh))
+               return (0);
+
        if (collect_user_count)
-       {
                numusers_submit(name, name, sum_users);
-               read = 1;
-       }
 
-       return (read);
+       return (1);
 } /* int multi1_read */
 
 /* for reading status version 2 */
@@ -522,9 +518,9 @@ static int multi4_read (char *name, FILE *fh)
 static int openvpn_read (void)
 {
        FILE *fh;
-       int  i, vpn_read, read;
+       int  i, read;
 
-       vpn_read = read = 0;
+       read = 0;
 
        /* call the right read function for every status entry in the list */
        for (i = 0; i < vpn_num; i++)
@@ -699,6 +695,14 @@ static int openvpn_config (const char *key, const char *value)
 
                /* create a new vpn element since file, version and name are ok */
                temp = (vpn_status_t *) malloc (sizeof (vpn_status_t));
+               if (temp == NULL)
+               {
+                       char errbuf[1024];
+                       ERROR ("openvpn plugin: malloc failed: %s",
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
+                       sfree (status_file);
+                       return (1);
+               }
                temp->file = status_file;
                temp->version = status_version;
                temp->name = status_name;
@@ -707,7 +711,7 @@ static int openvpn_config (const char *key, const char *value)
                if (vpn_list == NULL)
                {
                        char errbuf[1024];
-                       ERROR ("openvpn plugin: malloc failed: %s",
+                       ERROR ("openvpn plugin: realloc failed: %s",
                                        sstrerror (errno, errbuf, sizeof (errbuf)));
 
                        sfree (temp->file);