From 33ae98c96f9e9564085fd6fc49f9a77fcf0fa331 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Mon, 17 Dec 2012 02:37:44 +0200 Subject: Attempt to free plot data entries in each call to create_plot_info() In profile.c:create_plot_info(), store the last address in which memory was allocated for the plot data entries in the static variable "last_pi_entry". If "last_pi_entry" isn't a NULL pointer in each call to create_plot_info(), free memory at that address. Signed-off-by: Lubomir I. Ivanov Signed-off-by: Dirk Hohndel --- profile.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/profile.c b/profile.c index 984c5e2c9..a1f8c6bfb 100644 --- a/profile.c +++ b/profile.c @@ -22,6 +22,7 @@ int selected_dive = 0; char zoomed_plot = 0; static double plot_scale = SCALE_SCREEN; +static struct plot_data *last_pi_entry = NULL; #define cairo_set_line_width_scaled(cr, w) \ cairo_set_line_width((cr), (w) * plot_scale); @@ -1525,7 +1526,9 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer /* we want to potentially add synthetic plot_info elements for the gas changes */ nr = dc->samples + 4 + 2 * count_gas_change_events(dc); - pi->entry = calloc(nr, sizeof(struct plot_data)); + if (last_pi_entry) + free((void *)last_pi_entry); + last_pi_entry = pi->entry = calloc(nr, sizeof(struct plot_data)); if (!pi->entry) return NULL; pi->nr = nr; @@ -1879,7 +1882,7 @@ void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale) if (gc->printer) { free(pi->entry); - pi->entry = NULL; + last_pi_entry = pi->entry = NULL; pi->nr = 0; } } -- cgit v1.2.3-70-g09d2