diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2012-12-17 02:37:44 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-12-16 16:00:09 -1000 |
commit | 33ae98c96f9e9564085fd6fc49f9a77fcf0fa331 (patch) | |
tree | bae8fefe5c64e4a7eed695c0a073e25b7df07224 /profile.c | |
parent | 5c65ed2390d3772bd6773464c928e58b7585ba3c (diff) | |
download | subsurface-33ae98c96f9e9564085fd6fc49f9a77fcf0fa331.tar.gz |
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 <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile.c')
-rw-r--r-- | profile.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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; } } |