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 496895a..55f189a 100644 (file)
@@ -87,6 +87,7 @@ static void dccp_shutdown(void)
 {
        dccp_shutdown_clients();
        generic_acl_deplete(&dss->acl);
+       free_sender_status(dss);
 }
 
 /** * Obtain current MPS according to RFC 4340, sec. 14. */
index 330b45a..c6b9dec 100644 (file)
@@ -80,6 +80,7 @@ static void http_shutdown(void)
 {
        http_shutdown_clients();
        generic_acl_deplete(&hss->acl);
+       free_sender_status(hss);
 }
 
 static int queue_chunk_or_shutdown(struct sender_client *sc,
diff --git a/send.h b/send.h
index 8f7005c..f6aafbb 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);
+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);
index 24b14ab..ea494d9 100644 (file)
@@ -154,6 +154,25 @@ void init_sender_status(struct sender_status *ss,
        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.
  *