From 789eb2c62095a7488ff874284bb2830c1dc03673 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 4 Dec 2021 16:06:35 +0100 Subject: [PATCH] profile: clear plot_info structure when freeing data free_plot_info_data() frees the sample and pressure arrays and accordingly sets the corresponding pointers to NULL. However, it doesn't clear the element-count and thus leaves the structure in an inconsistent state. Clear the whole structure with memset(). I am not a fan of doing so, but there are existing memset() calls in the same source file, so let's keep it like that for consistency. Signed-off-by: Berthold Stoeger --- core/profile.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/profile.c b/core/profile.c index 51002dd65..d6eb855c2 100644 --- a/core/profile.c +++ b/core/profile.c @@ -395,8 +395,7 @@ void free_plot_info_data(struct plot_info *pi) { free(pi->entry); free(pi->pressures); - pi->entry = NULL; - pi->pressures = NULL; + memset(pi, 0, sizeof(*pi)); } static void populate_plot_entries(const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi)