while (g_hash_table_iter_next(&iter, NULL, &value))
g_free(value);
g_hash_table_unref(devc->ch_ag);
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
return std_scan_complete(di, devices);
}
-static void clear_helper(void *priv)
-{
- struct dev_context *devc;
-
- devc = priv;
- g_free(devc);
-}
-
-static int dev_clear(const struct sr_dev_driver *di)
-{
- return std_dev_clear_with_callback(di, clear_helper);
-}
-
static int dev_open(struct sr_dev_inst *sdi)
{
struct sr_dev_driver *di = sdi->driver;
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
- .dev_clear = dev_clear,
+ .dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,
devc = priv;
g_free(devc->data_buf);
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
devc = priv;
g_slist_free(devc->enabled_analog_channels);
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
g_free(devc->analog_groups);
g_free(devc->digital_groups);
-
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
devc = priv;
g_slist_free(devc->enabled_channels);
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
libusb_free_transfer(devc->xfer_in);
libusb_free_transfer(devc->xfer_out);
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
ftdi_free(devc->ftdic);
g_free(devc->compressed_buf);
g_free(devc->sample_buf);
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
lecroy_xstream_state_free(devc->model_state);
g_free(devc->analog_groups);
-
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
g_free(devc->trigger_source);
g_free(devc->trigger_slope);
g_free(devc->analog_groups);
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
devc = priv;
g_free(devc->channels);
g_free(devc->channel_groups);
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
return std_scan_complete(di, devices);
}
-static void clear_helper(void *priv)
-{
- struct dev_context *devc;
-
- devc = priv;
-
- if (devc->acquisition) {
- sr_err("Cannot clear device context during acquisition!");
- return; /* Leak and pray. */
- }
-
- g_free(devc);
-}
-
-static int dev_clear(const struct sr_dev_driver *di)
-{
- return std_dev_clear_with_callback(di, clear_helper);
-}
-
/* Drain any pending data from the USB transfer buffers on the device.
* This may be necessary e.g. after a crash or generally to clean up after
* an abnormal condition.
.cleanup = std_cleanup,
.scan = scan,
.dev_list = std_dev_list,
- .dev_clear = dev_clear,
+ .dev_clear = std_dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_channel_set = config_channel_set,
g_free(devc->analog_groups);
g_free(devc->digital_groups);
- g_free(devc);
}
static int dev_clear(const struct sr_dev_driver *di)
* This function can be used to implement the dev_clear() driver API
* callback. dev_close() is called before every sr_dev_inst is cleared.
*
- * The only limitation is driver-specific device contexts (sdi->priv).
+ * The only limitation is driver-specific device contexts (sdi->priv / devc).
* These are freed, but any dynamic allocation within structs stored
* there cannot be freed.
*
* @param[in] driver The driver which will have its instances released.
* Must not be NULL.
* @param[in] clear_private If not NULL, this points to a function called
- * with sdi->priv as argument. The function can then clear
+ * with sdi->priv (devc) as argument. The function can then clear
* any device instance-specific resources kept there.
- * It must also clear the struct pointed to by sdi->priv.
+ * It must NOT clear the struct pointed to by sdi->priv (devc),
+ * since this function will always free it after clear_private()
+ * has run.
*
* @retval SR_OK Success.
* @retval SR_ERR_ARG Invalid argument.
if (sdi->inst_type == SR_INST_MODBUS)
sr_modbus_free(sdi->conn);
}
+
+ /* Clear driver-specific stuff, if any. */
if (clear_private)
- /* The helper function is responsible for freeing
- * its own sdi->priv! */
clear_private(sdi->priv);
- else
- g_free(sdi->priv);
+
+ /* Clear sdi->priv (devc). */
+ g_free(sdi->priv);
sr_dev_inst_free(sdi);
}