subsurface/core/divelog.h
Berthold Stoeger e20ec9248c core: fix leak when clearing dive log
46cf2fc086 fixed a bug where clearing of a divelog, such as the one
used for import, would erase dives in the global(!) divelog.

However, the new code used the function clear_dive_table(), which
only cleared the table without unregistering the dives. In particular,
the dives were not removed from the trips, which means that the trips
were not free()d.

This reinstates the old code, but now passes a divelog paremeter
to delete_single_dive() instead of accessing the global divelog.
Moreover, delete dives from the back to avoid unnecessary
copying.

An alternative and definitely simpler solution might be to just
add a "clear_trip_table()" after "clear_dive_table()".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-05-13 08:58:03 +12:00

43 lines
897 B
C

// SPDX-License-Identifier: GPL-2.0
// A structure that contains all the values we save in a divelog file
#ifndef DIVELOG_H
#define DIVELOG_H
struct dive_table;
struct trip_table;
struct dive_site_table;
struct device_table;
struct filter_preset_table;
#include <stdbool.h>
struct divelog {
struct dive_table *dives;
struct trip_table *trips;
struct dive_site_table *sites;
struct device_table *devices;
struct filter_preset_table *filter_presets;
bool autogroup;
#ifdef __cplusplus
void clear();
divelog();
~divelog();
divelog(divelog &&log); // move constructor (argument is consumed).
divelog &operator=(divelog &&log); // move assignment (argument is consumed).
#endif
};
extern struct divelog divelog;
#ifdef __cplusplus
extern "C" {
#endif
void clear_divelog(struct divelog *);
extern void delete_single_dive(struct divelog *, int idx);
#ifdef __cplusplus
}
#endif
#endif