From 950436eba96551552978fc89de2d6968ed7b9bd8 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 2 Mar 2013 14:08:57 -0800 Subject: [PATCH] Don't duplicate gpsfixes if downloading them multiple times Simply clear out the table (and free the "dives" that were created). Reported-by: Sergey Starosek Signed-off-by: Dirk Hohndel --- webservice.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/webservice.c b/webservice.c index 2c8eea80e..be3e1d273 100644 --- a/webservice.c +++ b/webservice.c @@ -140,6 +140,14 @@ static void download_dialog_release_xml(struct download_dialog_state *state) free((void *)state->xmldata); } +static void clear_table(struct dive_table *table) +{ + int i; + for (i = 0; i < table->nr; i++) + free(table->dives[i]); + table->nr = 0; +} + static void download_dialog_response_cb(GtkDialog *d, gint response, gpointer data) { struct download_dialog_state *state = (struct download_dialog_state *)data; @@ -150,6 +158,7 @@ static void download_dialog_response_cb(GtkDialog *d, gint response, gpointer da break; case GTK_RESPONSE_ACCEPT: /* apply download */ + clear_table(&gps_location_table); parse_xml_buffer(_("Webservice"), state->xmldata, state->xmldata_len, &gps_location_table, NULL); /* now merge the data in the gps_location table into the dive_table */ if (merge_locations_into_dives()) {