summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Golubev <fatzer2@gmail.com>2024-03-17 03:51:37 +0300
committerPeter Hutterer <peter.hutterer@who-t.net>2024-03-18 11:24:46 +1000
commit6afd4ae4473e7c1701ae3be9813ca2857395f2a5 (patch)
treeff35b9714594565237729334a6eb742eab3dab4d
parent893788c14a36a7a524659652f0f41439b583bd3d (diff)
Add XkbRF_FreeVarDefs() a destructor for XkbRF_VarDefsRec.
The function properly frees memory allocated for XkbRF_VarDefsRec by XkbRF_GetNamesProp(). Based on original contribution by Martin Weber <martin.weber@secunet.com> Closes: https://gitlab.freedesktop.org/xorg/lib/libxkbfile/-/issues/6 Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
-rw-r--r--include/X11/extensions/XKBrules.h12
-rw-r--r--src/maprules.c28
2 files changed, 39 insertions, 1 deletions
diff --git a/include/X11/extensions/XKBrules.h b/include/X11/extensions/XKBrules.h
index 4736056..8580b55 100644
--- a/include/X11/extensions/XKBrules.h
+++ b/include/X11/extensions/XKBrules.h
@@ -191,6 +191,18 @@ extern Bool XkbRF_SetNamesProp(
XkbRF_VarDefsPtr /* var_defs */
);
+/**
+ * @brief Destroy @struct XkbRF_VarDefsRec
+ * @param[in] var_defs - a XkbRF_VarDefsRec to clean up
+ * @param[in] freeVarDefs - if @c True also free the @p var_defs itself
+ *
+ * Frees the memory associated with the @p var_defs. If @p free_var_defs is
+ * @c True also frees the @p var_defs pointer itself.
+ */
+extern void XkbRF_FreeVarDefs(
+ XkbRF_VarDefsPtr /* var_defs */,
+ Bool /* freeVarDefs */
+);
_XFUNCPROTOEND
diff --git a/src/maprules.c b/src/maprules.c
index bd83f71..7e5bbd5 100644
--- a/src/maprules.c
+++ b/src/maprules.c
@@ -1458,7 +1458,10 @@ XkbRF_GetNamesProp(Display * dpy, char **rf_rtrn, XkbRF_VarDefsPtr vd_rtrn)
vd_rtrn->options = _XkbDupString(out);
out += strlen(out) + 1;
}
-
+ /*
+ * For now extra_options and extra_rules are not used
+ * update XkbRF_FreeVarDefs if that changes
+ */
XFree(data);
return True;
}
@@ -1528,3 +1531,26 @@ XkbRF_SetNamesProp(Display *dpy, char *rules_file, XkbRF_VarDefsPtr var_defs)
return True;
}
+void
+XkbRF_FreeVarDefs(XkbRF_VarDefsPtr var_defs, Bool freeVarDefs)
+{
+ if (!var_defs)
+ return;
+
+ _XkbFree(var_defs->model);
+ var_defs->model = NULL;
+ _XkbFree(var_defs->layout);
+ var_defs->layout = NULL;
+ _XkbFree(var_defs->variant);
+ var_defs->variant = NULL;
+ _XkbFree(var_defs->options);
+ var_defs->options = NULL;
+
+ _XkbFree(var_defs->extra_names);
+ var_defs->extra_names = NULL;
+ _XkbFree(var_defs->extra_values);
+ var_defs->extra_values = NULL;
+
+ if(freeVarDefs)
+ _XkbFree(var_defs);
+}