Cleanup: fix memory management of the plot data

There was a global variable last_pi_entry_new, which stored the
recently allocated plot data. This was freed when new plot data
was generated.

A very scary proposition: You can never have two plot datas at
the same time! But exactly that happens when you export for
example subtitles.

The only reason why this didn't lead to very crazy behavior
is that at least on my Linux machine, the calloc() call would
just return the previously freed memory.

Fix this mess by removing the global variable and freeing the
data in the callers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-07-06 14:41:09 +02:00 committed by Dirk Hohndel
parent 5e9ffe3005
commit 69be1e23f2
4 changed files with 16 additions and 11 deletions

View file

@ -636,6 +636,7 @@ void ProfileWidget2::plotDive(const struct dive *d, bool force, bool doClearPict
* shown.
*/
free_plot_info_data(&plotInfo);
plotInfo = calculate_max_limits_new(&displayed_dive, currentdc);
#ifndef SUBSURFACE_MOBILE
create_plot_info_new(&displayed_dive, currentdc, &plotInfo, !shouldCalculateMaxDepth, &DivePlannerPointsModel::instance()->final_deco_state);