summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2024-08-26 12:40:48 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2024-08-26 12:40:48 -0700
commitb8229647395b33b851ea1a52af95c9183c170d96 (patch)
tree6aad4ae462992ffd99686a158f6976e9e33f8de0 /src
parentccdc50c37ce068679746fb9a27fbfb21c96c171e (diff)
XkbRF_AddVarToDescribe: avoid memory leak if only one of the malloc fails
If one malloc failed and the other succeeded, we assumed both failed, and let the successful one leak. Found by gcc 14.1: maprules.c: In function ‘XkbRF_AddVarToDescribe’: maprules.c:1125:22: warning: leak of ‘<unknown>’ [CWE-401] [-Wanalyzer-malloc-leak] 1125 | rules->extra = NULL; | ^ Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Part-of: <https://gitlab.freedesktop.org/xorg/lib/libxkbfile/-/merge_requests/20>
Diffstat (limited to 'src')
-rw-r--r--src/maprules.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/maprules.c b/src/maprules.c
index ab1b383..33b544c 100644
--- a/src/maprules.c
+++ b/src/maprules.c
@@ -1121,7 +1121,9 @@ XkbRF_AddVarToDescribe(XkbRF_RulesPtr rules, char *name)
if ((!rules->extra_names) || (!rules->extra)) {
PR_DEBUG("allocation error in extra parts\n");
rules->sz_extra = rules->num_extra = 0;
+ free(rules->extra_names);
rules->extra_names = NULL;
+ free(rules->extra);
rules->extra = NULL;
return NULL;
}