diff --git a/src/openvpn.c b/src/openvpn.c
index ec76a7aa66b5f69f749c6add9adfd15adf8187be..00ae736ad4b01c70555f509c0b3580afb8fa8329 100644 (file)
--- a/src/openvpn.c
+++ b/src/openvpn.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
static int openvpn_read (void)
{
FILE *fh;
- int i, read;
+ int read;
read = 0;
/* call the right read function for every status entry in the list */
- for (i = 0; i < vpn_num; i++)
+ for (int i = 0; i < vpn_num; i++)
{
int vpn_read = 0;
if (strcasecmp ("StatusFile", key) == 0)
{
char *status_file, *status_name, *filename;
- int status_version, i;
+ int status_version;
vpn_status_t *temp;
/* try to detect the status file format */
}
/* scan the list looking for a clone */
- for (i = 0; i < vpn_num; i++)
+ for (int i = 0; i < vpn_num; i++)
{
if (strcasecmp (vpn_list[i]->name, status_name) == 0)
{
temp->version = status_version;
temp->name = status_name;
- vpn_list = (vpn_status_t **) realloc (vpn_list, (vpn_num + 1) * sizeof (vpn_status_t *));
- if (vpn_list == NULL)
+ vpn_status_t **tmp_list = realloc (vpn_list, (vpn_num + 1) * sizeof (*vpn_list));
+ if (tmp_list == NULL)
{
char errbuf[1024];
ERROR ("openvpn plugin: realloc failed: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
+ sfree (vpn_list);
sfree (temp->file);
sfree (temp);
return (1);
}
+ vpn_list = tmp_list;
vpn_list[vpn_num] = temp;
vpn_num++;
/* shutdown callback */
static int openvpn_shutdown (void)
{
- int i;
-
- for (i = 0; i < vpn_num; i++)
+ for (int i = 0; i < vpn_num; i++)
{
sfree (vpn_list[i]->file);
sfree (vpn_list[i]);