From: Andre Noll Date: Sun, 1 Sep 2019 12:26:40 +0000 (+0200) Subject: vss: Fix harmless memory leaks at exit. X-Git-Tag: v0.6.3~30 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=4fb6bf35f5dd6bfcafc0b90e83d4d9084da38365;ds=sidebyside vss: Fix harmless memory leaks at exit. The leaks were introduced in commit 4fbe16430b47 (server: Add --http-listen-address and --dccp-listen-address) from last year. Found by valgrind. --- diff --git a/dccp_send.c b/dccp_send.c index 496895a5..55f189ad 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -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. */ diff --git a/http_send.c b/http_send.c index 330b45ac..c6b9decc 100644 --- a/http_send.c +++ b/http_send.c @@ -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 8f7005cd..f6aafbb4 100644 --- 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); diff --git a/send_common.c b/send_common.c index 24b14ab8..ea494d9a 100644 --- a/send_common.c +++ b/send_common.c @@ -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. *