demo: Provide dev_clear()

Devices for the demo driver do have additional data attached to it that
needs to be freed when the device is freed. While the driver gets it right
for the cleanup() callback it does not implement a dev_clear() callback, so
the default dev_clear() implementation is used which will not free the
additional data. This will cause memory leaks when sr_dev_clear() is called
for this driver.

To fix this provide a dev_clear() implementation that frees the additional
data.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2016-04-29 16:28:59 +02:00
parent 74c6d807ef
commit 6ab687315b
1 changed files with 7 additions and 2 deletions

View File

@ -389,11 +389,16 @@ static void clear_helper(void *priv)
g_free(devc);
}
static int cleanup(const struct sr_dev_driver *di)
static int dev_clear(const struct sr_dev_driver *di)
{
return std_dev_clear(di, clear_helper);
}
static int cleanup(const struct sr_dev_driver *di)
{
return dev_clear(di);
}
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
const struct sr_channel_group *cg)
{
@ -892,7 +897,7 @@ SR_PRIV struct sr_dev_driver demo_driver_info = {
.cleanup = cleanup,
.scan = scan,
.dev_list = dev_list,
.dev_clear = NULL,
.dev_clear = dev_clear,
.config_get = config_get,
.config_set = config_set,
.config_list = config_list,