From 08827cc5f6063a2e3720b9d821c9146fac74a0bd Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 14 Oct 2018 23:30:31 +0200 Subject: Parser: fix leakage of dive-site and dive data Dive site data was collected in "cur_dive_site", which was then merged into an existing or a new dive site. But only the struct dive_site pointed to by "cur_dive_site" and the taxonomy data were freed, not the textual data such as name or description. Therefore, split out the approrpriate free-ing from the delete_dive_site() function and call that instead of a simple free(). A similar situation occured for dives that would not be added to the dive-table because they were deemed incomplete. Use free_dive() here instead of a simple free() too. Signed-off-by: Berthold Stoeger --- core/divesite.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'core/divesite.c') diff --git a/core/divesite.c b/core/divesite.c index f634044c2..c41b18220 100644 --- a/core/divesite.c +++ b/core/divesite.c @@ -40,7 +40,6 @@ uint32_t get_dive_site_uuid_by_gps(degrees_t latitude, degrees_t longitude, stru return 0; } - /* to avoid a bug where we have two dive sites with different name and the same GPS coordinates * and first get the gps coordinates (reading a V2 file) and happen to get back "the other" name, * this function allows us to verify if a very specific name/GPS combination already exists */ @@ -167,16 +166,22 @@ bool is_dive_site_used(uint32_t uuid, bool select_only) return found; } +void free_dive_site(struct dive_site *ds) +{ + free(ds->name); + free(ds->notes); + free(ds->description); + free_taxonomy(&ds->taxonomy); + free(ds); +} + void delete_dive_site(uint32_t id) { int nr = dive_site_table.nr; for (int i = 0; i < nr; i++) { struct dive_site *ds = get_dive_site(i); if (ds->uuid == id) { - free(ds->name); - free(ds->notes); - free_taxonomy(&ds->taxonomy); - free(ds); + free_dive_site(ds); if (nr - 1 > i) memmove(&dive_site_table.dive_sites[i], &dive_site_table.dive_sites[i+1], -- cgit v1.2.3-70-g09d2