vss: Fix harmless memory leaks at exit.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 1 Sep 2019 12:26:40 +0000 (14:26 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 8 Dec 2019 08:51:01 +0000 (09:51 +0100)
The leaks were introduced in commit 4fbe16430b47 (server: Add
--http-listen-address and --dccp-listen-address) from last year.

Found by valgrind.

dccp_send.c
http_send.c
send.h
send_common.c

index 496895a509f15466e7430af454c784a09bc3ce7e..55f189ad4eb01632dbcd653e104ef7f0cfe54ff8 100644 (file)
@@ -87,6 +87,7 @@ static void dccp_shutdown(void)
 {
        dccp_shutdown_clients();
        generic_acl_deplete(&dss->acl);
 {
        dccp_shutdown_clients();
        generic_acl_deplete(&dss->acl);
+       free_sender_status(dss);
 }
 
 /** * Obtain current MPS according to RFC 4340, sec. 14. */
 }
 
 /** * Obtain current MPS according to RFC 4340, sec. 14. */
index 330b45ac1b3ec675a497796be614c07c0bbd9c36..c6b9decca941489c82b629982ddb6d6dbdb2ea33 100644 (file)
@@ -80,6 +80,7 @@ static void http_shutdown(void)
 {
        http_shutdown_clients();
        generic_acl_deplete(&hss->acl);
 {
        http_shutdown_clients();
        generic_acl_deplete(&hss->acl);
+       free_sender_status(hss);
 }
 
 static int queue_chunk_or_shutdown(struct sender_client *sc,
 }
 
 static int queue_chunk_or_shutdown(struct sender_client *sc,
diff --git a/send.h b/send.h
index 8f7005cdaa78f0909808932e602fc7de7945dd52..f6aafbb41a2bf9b089f2ddcc9968278dea734fa1 100644 (file)
--- a/send.h
+++ b/send.h
@@ -212,6 +212,7 @@ void init_sender_status(struct sender_status *ss,
                const struct lls_opt_result *acl_opt_result,
                const struct lls_opt_result *listen_address_opt_result,
                int default_port, int max_clients, int default_deny);
                const struct lls_opt_result *acl_opt_result,
                const struct lls_opt_result *listen_address_opt_result,
                int default_port, int max_clients, int default_deny);
+void free_sender_status(const struct sender_status *ss);
 char *generic_sender_status(struct sender_status *ss, const char *name);
 void generic_com_allow(struct sender_command_data *scd,
                struct sender_status *ss);
 char *generic_sender_status(struct sender_status *ss, const char *name);
 void generic_com_allow(struct sender_command_data *scd,
                struct sender_status *ss);
index 24b14ab8ed50b90c956fc6578199f8a4da3f2c4e..ea494d9a7b23f5ee87186917d11e883631ec9cbc 100644 (file)
@@ -154,6 +154,25 @@ void init_sender_status(struct sender_status *ss,
        ss->default_deny = default_deny;
 }
 
        ss->default_deny = default_deny;
 }
 
+/**
+ * Deallocate all resources allocated in \ref init_sender_status().
+ *
+ * \param ss The structure whose components should be freed.
+ *
+ * This frees the dynamically allocated parts of the structure which was
+ * initialized by an earlier call to \ref init_sender_status(). It does *not*
+ * call free(ss), though.
+ */
+void free_sender_status(const struct sender_status *ss)
+{
+       int i;
+
+       free(ss->listen_fds);
+       FOR_EACH_LISTEN_FD(i, ss)
+               free(ss->listen_addresses[i]);
+       free(ss->listen_addresses);
+}
+
 /**
  * Return a string containing the current status of a sender.
  *
 /**
  * Return a string containing the current status of a sender.
  *