hidpp20: implement hidpp20_onboard_profiles_destroy to free memory

Macros will be dynamically allocated, so we need a way to free them
reliably.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
This commit is contained in:
Benjamin Tissoires
2015-12-16 14:17:13 +01:00
parent 4673b62eb4
commit 94062a0881
3 changed files with 21 additions and 2 deletions

View File

@@ -734,11 +734,12 @@ static void
hidpp20drv_remove(struct ratbag_device *device)
{
struct hidpp20drv_data *drv_data = ratbag_get_drv_data(device);
struct hidpp20_device *dev = drv_data->dev;
ratbag_close_hidraw(device);
if (drv_data->profiles)
free(drv_data->profiles);
hidpp20_onboard_profiles_destroy(dev, drv_data->profiles);
free(drv_data->controls);
free(drv_data->sensors);
hidpp20_device_destroy(drv_data->dev);

View File

@@ -1173,6 +1173,16 @@ hidpp20_onboard_profiles_allocate(struct hidpp20_device *device,
return profile_count;
}
void
hidpp20_onboard_profiles_destroy(struct hidpp20_device *device,
struct hidpp20_profiles *profiles_list)
{
if (!profiles_list)
return;
free(profiles_list);
}
static int
hidpp20_onboard_profiles_find_and_read_profile(struct hidpp20_device *device,
unsigned int index,

View File

@@ -327,13 +327,21 @@ struct hidpp20_profiles {
};
/**
* allocates a list of profiles that has to be freed by the caller.
* allocates a list of profiles that has to be destroyed by the caller.
* The caller must use hidpp20_onboard_profiles_destroy() to free the memory.
*
* returns the number of profiles in the list or a negative error
*/
int hidpp20_onboard_profiles_allocate(struct hidpp20_device *device,
struct hidpp20_profiles **profiles_list);
/**
* free a list of profiles allocated by hidpp20_onboard_profiles_allocate()
*/
void
hidpp20_onboard_profiles_destroy(struct hidpp20_device *device,
struct hidpp20_profiles *profiles_list);
/**
* return the current profile index or a negative error.
*/