xfree86: simplify match group destruction

Reducing repeated code patterns by simple function call.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult
2025-07-22 11:59:02 +02:00
committed by Enrico Weigelt
parent d46e9acd6f
commit e0440a0b42
3 changed files with 34 additions and 72 deletions

View File

@@ -32,7 +32,7 @@
#include "os/fmt.h"
#include "os.h"
#include "xf86Parser.h"
#include "xf86Parser_priv.h"
#include "xf86tokens.h"
#include "Configint.h"
@@ -76,66 +76,18 @@ xf86freeInputClassList(XF86ConfInputClassPtr ptr)
XF86ConfInputClassPtr prev;
while (ptr) {
xf86MatchGroup *group, *next;
char **list;
TestFree(ptr->identifier);
TestFree(ptr->driver);
xorg_list_for_each_entry_safe(group, next, &ptr->match_product, entry) {
xorg_list_del(&group->entry);
for (list = group->values; *list; list++)
free(*list);
free(group);
}
xorg_list_for_each_entry_safe(group, next, &ptr->match_vendor, entry) {
xorg_list_del(&group->entry);
for (list = group->values; *list; list++)
free(*list);
free(group);
}
xorg_list_for_each_entry_safe(group, next, &ptr->match_device, entry) {
xorg_list_del(&group->entry);
for (list = group->values; *list; list++)
free(*list);
free(group);
}
xorg_list_for_each_entry_safe(group, next, &ptr->match_os, entry) {
xorg_list_del(&group->entry);
for (list = group->values; *list; list++)
free(*list);
free(group);
}
xorg_list_for_each_entry_safe(group, next, &ptr->match_pnpid, entry) {
xorg_list_del(&group->entry);
for (list = group->values; *list; list++)
free(*list);
free(group);
}
xorg_list_for_each_entry_safe(group, next, &ptr->match_usbid, entry) {
xorg_list_del(&group->entry);
for (list = group->values; *list; list++)
free(*list);
free(group);
}
xorg_list_for_each_entry_safe(group, next, &ptr->match_driver, entry) {
xorg_list_del(&group->entry);
for (list = group->values; *list; list++)
free(*list);
free(group);
}
xorg_list_for_each_entry_safe(group, next, &ptr->match_tag, entry) {
xorg_list_del(&group->entry);
for (list = group->values; *list; list++)
free(*list);
free(group);
}
xorg_list_for_each_entry_safe(group, next, &ptr->match_layout, entry) {
xorg_list_del(&group->entry);
for (list = group->values; *list; list++)
free(*list);
free(group);
}
xf86freeMatchGroupList(&ptr->match_product);
xf86freeMatchGroupList(&ptr->match_vendor);
xf86freeMatchGroupList(&ptr->match_device);
xf86freeMatchGroupList(&ptr->match_os);
xf86freeMatchGroupList(&ptr->match_pnpid);
xf86freeMatchGroupList(&ptr->match_usbid);
xf86freeMatchGroupList(&ptr->match_driver);
xf86freeMatchGroupList(&ptr->match_tag);
xf86freeMatchGroupList(&ptr->match_layout);
TestFree(ptr->comment);
xf86optionListFree(ptr->option_lst);

View File

@@ -30,7 +30,7 @@
#include "os/fmt.h"
#include "os.h"
#include "xf86Parser.h"
#include "xf86Parser_priv.h"
#include "xf86tokens.h"
#include "Configint.h"
@@ -50,24 +50,12 @@ xf86freeOutputClassList(XF86ConfOutputClassPtr ptr)
XF86ConfOutputClassPtr prev;
while (ptr) {
xf86MatchGroup *group, *next;
char **list;
TestFree(ptr->identifier);
TestFree(ptr->comment);
TestFree(ptr->driver);
TestFree(ptr->modulepath);
xorg_list_for_each_entry_safe(group, next, &ptr->match_driver, entry) {
for (list = group->values; *list; list++) {
free(*list);
*list = NULL;
}
xorg_list_del(&group->entry);
free(group);
group = NULL;
}
xf86freeMatchGroupList(&ptr->match_driver);
xf86optionListFree(ptr->option_lst);
prev = ptr;

View File

@@ -6,6 +6,8 @@
#ifndef _XSERVER_XF86_PARSER_PRIV
#define _XSERVER_XF86_PARSER_PRIV
#include <stdlib.h>
#include "xf86Parser.h"
void xf86initConfigFiles(void);
@@ -23,4 +25,24 @@ void xf86freeConfig(XF86ConfigPtr p);
int xf86writeConfigFile(const char *filename, XF86ConfigPtr cptr);
int xf86layoutAddInputDevices(XF86ConfigPtr config, XF86ConfLayoutPtr layout);
static inline void xf86freeMatchGroup(xf86MatchGroup *group)
{
xorg_list_del(&group->entry);
if (group->values) {
for (char **list = group->values; *list; list++) {
free(*list);
*list = NULL;
}
group->values = NULL;
}
free(group);
}
static inline void xf86freeMatchGroupList(struct xorg_list *grouplist) {
xf86MatchGroup *group, *next;
xorg_list_for_each_entry_safe(group, next, grouplist, entry) {
xf86freeMatchGroup(group);
}
}
#endif /* _XSERVER_XF86_PARSER_PRIV */