X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fopenvpn.c;h=85760e996d27b8cd6a6cce3abb531631ad908ab1;hb=b81104a423234c04f0eb4ace0ec5e93a363c917a;hp=663a82d8fd9221fd6b138361efb03b340dc3666f;hpb=f9a6df05238501ca41931af0d8d51acea716c105;p=collectd.git diff --git a/src/openvpn.c b/src/openvpn.c index 663a82d8..85760e99 100644 --- a/src/openvpn.c +++ b/src/openvpn.c @@ -95,7 +95,8 @@ static int openvpn_strsplit (char *string, char **fields, size_t size) } /* int openvpn_strsplit */ /* dispatches number of users */ -static void numusers_submit (char *pinst, char *tinst, gauge_t value) +static void numusers_submit (const char *pinst, const char *tinst, + gauge_t value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; @@ -115,8 +116,10 @@ static void numusers_submit (char *pinst, char *tinst, gauge_t value) plugin_dispatch_values (&vl); } /* void numusers_submit */ -/* dispatches stats about traffic (TCP or UDP) generated by the tunnel per single endpoint */ -static void iostats_submit (char *pinst, char *tinst, derive_t rx, derive_t tx) +/* dispatches stats about traffic (TCP or UDP) generated by the tunnel + * per single endpoint */ +static void iostats_submit (const char *pinst, const char *tinst, + derive_t rx, derive_t tx) { value_t values[2]; value_list_t vl = VALUE_LIST_INIT; @@ -145,7 +148,7 @@ static void iostats_submit (char *pinst, char *tinst, derive_t rx, derive_t tx) } /* void traffic_submit */ /* dispatches stats about data compression shown when in single mode */ -static void compression_submit (char *pinst, char *tinst, +static void compression_submit (const char *pinst, const char *tinst, derive_t uncompressed, derive_t compressed) { value_t values[2]; @@ -168,7 +171,7 @@ static void compression_submit (char *pinst, char *tinst, plugin_dispatch_values (&vl); } /* void compression_submit */ -static int single_read (char *name, FILE *fh) +static int single_read (const char *name, FILE *fh) { char buffer[1024]; char *fields[4]; @@ -261,7 +264,7 @@ static int single_read (char *name, FILE *fh) } /* int single_read */ /* for reading status version 1 */ -static int multi1_read (char *name, FILE *fh) +static int multi1_read (const char *name, FILE *fh) { char buffer[1024]; char *fields[10]; @@ -324,7 +327,7 @@ static int multi1_read (char *name, FILE *fh) } /* int multi1_read */ /* for reading status version 2 */ -static int multi2_read (char *name, FILE *fh) +static int multi2_read (const char *name, FILE *fh) { char buffer[1024]; char *fields[10]; @@ -386,7 +389,7 @@ static int multi2_read (char *name, FILE *fh) } /* int multi2_read */ /* for reading status version 3 */ -static int multi3_read (char *name, FILE *fh) +static int multi3_read (const char *name, FILE *fh) { char buffer[1024]; char *fields[15]; @@ -451,7 +454,7 @@ static int multi3_read (char *name, FILE *fh) } /* int multi3_read */ /* for reading status version 4 */ -static int multi4_read (char *name, FILE *fh) +static int multi4_read (const char *name, FILE *fh) { char buffer[1024]; char *fields[11]; @@ -696,22 +699,32 @@ 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)); + temp = malloc (sizeof (*temp)); + 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; - 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: malloc failed: %s", + 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++;