email plugin: Free "connection" in error handling.
authorFlorian Forster <octo@collectd.org>
Tue, 8 Dec 2015 10:56:09 +0000 (11:56 +0100)
committerFlorian Forster <octo@collectd.org>
Tue, 8 Dec 2015 10:56:09 +0000 (11:56 +0100)
CID: 38010

src/email.c

index fdcf067..7493cc6 100644 (file)
@@ -520,13 +520,20 @@ static void *open_connection (void __attribute__((unused)) *arg)
                        }
                } while (EINTR == errno);
 
-               connection = (conn_t *)smalloc (sizeof (conn_t));
+               connection = malloc (sizeof (*connection));
+               if (connection != NULL)
+               {
+                       close (remote);
+                       continue;
+               }
+               memset (connection, 0, sizeof (*connection));
 
                connection->socket = fdopen (remote, "r");
                connection->next   = NULL;
 
                if (NULL == connection->socket) {
                        close (remote);
+                       sfree (connection);
                        continue;
                }