diff --git a/core/libdivecomputer.cpp b/core/libdivecomputer.cpp index e3b2bc1e2..081218f16 100644 --- a/core/libdivecomputer.cpp +++ b/core/libdivecomputer.cpp @@ -55,6 +55,16 @@ static int current_gas_index; #define INFO(fmt, ...) report_info("INFO: " fmt, ##__VA_ARGS__) #define ERROR(fmt, ...) report_info("ERROR: " fmt, ##__VA_ARGS__) +device_data_t::device_data_t() +{ +} + +device_data_t::~device_data_t() +{ + if (descriptor) + dc_descriptor_free(descriptor); +} + /* * Directly taken from libdivecomputer's examples/common.c to improve * the error messages resulting from libdc's return codes diff --git a/core/libdivecomputer.h b/core/libdivecomputer.h index 9556edd3b..38b9019da 100644 --- a/core/libdivecomputer.h +++ b/core/libdivecomputer.h @@ -29,7 +29,7 @@ struct dive; struct divelog; struct devices; -typedef struct { +struct device_data_t { dc_descriptor_t *descriptor = nullptr; std::string vendor, product, devname; std::string model, btname; @@ -48,7 +48,9 @@ typedef struct { FILE *libdc_logfile = nullptr; struct divelog *log = nullptr; void *androidUsbDeviceDescriptor = nullptr; -} device_data_t; + device_data_t(); + ~device_data_t(); +}; const char *errmsg (dc_status_t rc); std::string do_libdivecomputer_import(device_data_t *data); diff --git a/smtk-import/smartrak.cpp b/smtk-import/smartrak.cpp index ce8773ca9..58192683f 100644 --- a/smtk-import/smartrak.cpp +++ b/smtk-import/smartrak.cpp @@ -842,11 +842,6 @@ static dc_status_t prepare_data(int data_model, const char *serial, dc_family_t } } -static void device_data_free(device_data_t &dev_data) -{ - dc_descriptor_free(dev_data.descriptor); -} - /* * Returns a buffer prepared for libdc parsing. * Aladin and memomouse dives were imported from datatrak, so they lack of a @@ -1048,7 +1043,6 @@ extern "C" void smartrak_import(const char *file, struct divelog *log) concat(&smtkdive->notes, "\n", std::string((char *)col[coln(REMARKS)]->bind_ptr)); record_dive_to_table(smtkdive, log->dives); - device_data_free(devdata); } mdb_free_catalog(mdb_clon); mdb->catalog = NULL;