From a592c04ffa874bb66507277e1af1a7a55d447f21 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Tue, 9 Dec 2025 10:30:24 +0200 Subject: [PATCH] Change: free report printing context using a function Instead of freeing the zone data in tz_revert, free it with a new function. Eventually there will be more data in here, so it makes sense to free it in one place. This also allows freeing the tz data in the success case, which was missing. --- src/manage_sql.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index c93628a00..7b86a4319 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -16769,9 +16769,6 @@ tz_revert (gchar *zone, char *tz, char *old_tz_override) if (setenv ("TZ", tz, 1) == -1) { g_warning ("%s: Failed to switch to original TZ", __func__); - g_free (tz); - g_free (zone); - free (old_tz_override); return -1; } } @@ -16782,11 +16779,7 @@ tz_revert (gchar *zone, char *tz, char *old_tz_override) sql ("SET SESSION \"gvmd.tz_override\" = %s;", quoted_old_tz_override); g_free (quoted_old_tz_override); - - free (old_tz_override); - g_free (tz); } - g_free (zone); return 0; } @@ -17543,6 +17536,19 @@ struct print_report_context */ typedef struct print_report_context print_report_context_t; +/** + * @brief Free the members of a context. + * + * @param[in] ctx Printing context. + */ +static void +print_report_context_cleanup (print_report_context_t *ctx) +{ + g_free (ctx->tz); + g_free (ctx->zone); + free (ctx->old_tz_override); +} + /** * @brief Init zone info for print_report_xml_start. * @@ -18879,6 +18885,8 @@ print_report_xml_start (report_t report, report_t delta, task_t task, if (host_summary && host_summary_buffer) *host_summary = g_string_free (host_summary_buffer, FALSE); + print_report_context_cleanup (&ctx); + if (fclose (out)) { g_warning ("%s: fclose failed: %s", @@ -18921,6 +18929,7 @@ print_report_xml_start (report_t report, report_t delta, task_t task, } fail: tz_revert (ctx.zone, ctx.tz, ctx.old_tz_override); + print_report_context_cleanup (&ctx); fclose (out); return -1; }