X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fteamspeak2.c;h=cf093c5feec35debf969b27d4c1fac8b432b20ba;hb=3fae5596643f1e361eb18c3d65448f8bc02fdd80;hp=058eb7c38362a7cc972ca609556698e1537933f6;hpb=17b60946497048b34b417aa0497607f3aa6a34f3;p=collectd.git diff --git a/src/teamspeak2.c b/src/teamspeak2.c index 058eb7c3..cf093c5f 100644 --- a/src/teamspeak2.c +++ b/src/teamspeak2.c @@ -83,13 +83,12 @@ static int tss2_add_vserver (int vserver_port) } /* Allocate memory */ - entry = (vserver_list_t *) malloc (sizeof (vserver_list_t)); + entry = calloc (1, sizeof (*entry)); if (entry == NULL) { - ERROR ("teamspeak2 plugin: malloc failed."); + ERROR ("teamspeak2 plugin: calloc failed."); return (-1); } - memset (entry, 0, sizeof (vserver_list_t)); /* Save data */ entry->port = vserver_port; @@ -140,7 +139,7 @@ static void tss2_submit_gauge (const char *plugin_instance, if (type_instance != NULL) sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - + plugin_dispatch_values (&vl); } /* void tss2_submit_gauge */ @@ -199,7 +198,7 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh) * Returns connected file objects or establishes the connection * if it's not already present */ - struct addrinfo ai_hints; + struct addrinfo ai_hints = { 0 }; struct addrinfo *ai_head; struct addrinfo *ai_ptr; int sd = -1; @@ -217,7 +216,6 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh) } /* Get all addrs for this hostname */ - memset (&ai_hints, 0, sizeof (ai_hints)); #ifdef AI_ADDRCONFIG ai_hints.ai_flags |= AI_ADDRCONFIG; #endif @@ -352,7 +350,7 @@ static int tss2_receive_line (FILE *fh, char *buffer, int buffer_size) * Receive a single line from the given file object */ char *temp; - + /* * fgets is blocking but much easier then doing anything else * TODO: Non-blocking Version would be safer @@ -435,7 +433,7 @@ static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh, char buffer[4096]; char *value; char *endptr = NULL; - + status = tss2_receive_line (read_fh, buffer, sizeof (buffer)); if (status != 0) { @@ -446,7 +444,7 @@ static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh, return (-1); } buffer[sizeof (buffer) - 1] = 0; - + if (strncmp ("average_packet_loss=", buffer, strlen ("average_packet_loss=")) == 0) { @@ -462,9 +460,9 @@ static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh, } value++; } - + value = &buffer[20]; - + packet_loss = strtod (value, &endptr); if (value == endptr) { @@ -489,7 +487,7 @@ static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh, buffer); } } - + *ret_value = packet_loss; return (0); } /* int tss2_vserver_gapl */ @@ -512,7 +510,7 @@ static int tss2_read_vserver (vserver_list_t *vserver) gauge_t packet_loss = NAN; int valid = 0; - char plugin_instance[DATA_MAX_NAME_LEN]; + char plugin_instance[DATA_MAX_NAME_LEN] = { 0 }; FILE *read_fh; FILE *write_fh; @@ -528,8 +526,6 @@ static int tss2_read_vserver (vserver_list_t *vserver) if (vserver == NULL) { /* Request global information */ - memset (plugin_instance, 0, sizeof (plugin_instance)); - status = tss2_send_request (write_fh, "gi\r\n"); } else @@ -559,7 +555,7 @@ static int tss2_read_vserver (vserver_list_t *vserver) char *key; char *value; char *endptr = NULL; - + /* Read one line of the server's answer */ status = tss2_receive_line (read_fh, buffer, sizeof (buffer)); if (status != 0) @@ -724,7 +720,7 @@ static int tss2_config (const char *key, const char *value) /* * Interpret configuration values */ - if (strcasecmp ("Host", key) == 0) + if (strcasecmp ("Host", key) == 0) { char *temp; @@ -754,7 +750,7 @@ static int tss2_config (const char *key, const char *value) { /* Server variable found */ int status; - + status = tss2_add_vserver (atoi (value)); if (status != 0) return (1); @@ -804,10 +800,10 @@ static int tss2_read (void) continue; } } - + if (success == 0) return (-1); - return (0); + return (0); } /* int tss2_read */ static int tss2_shutdown(void) @@ -833,7 +829,7 @@ static int tss2_shutdown(void) /* Get rid of the configuration */ sfree (config_host); sfree (config_port); - + return (0); } /* int tss2_shutdown */