summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-10-08 12:20:59 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-10-08 12:20:59 -0700
commit8f5e188675d81a8310a1f50f0675a7d421cc53e9 (patch)
tree39ae42283299826b9ce461d3aa027524c766f83f
parentd4eef750160356c8a9dc55d5e28c3546f8ef5418 (diff)
XkbWriteCFile: stop leaking header file ifdef name
Found by gcc 12 analyzer: cout.c:1106:8: warning: leak of ‘hdrdef’ [CWE-401] [-Wanalyzer-malloc-leak] 1106 | if (!ok) { | ^ Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--src/cout.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/cout.c b/src/cout.c
index ce34366..a0fb8d4 100644
--- a/src/cout.c
+++ b/src/cout.c
@@ -1074,9 +1074,8 @@ XkbWriteCFile(FILE *out, char *name, XkbFileInfo *result)
tmp = name;
else
tmp++;
- hdrdef = (char *) _XkbCalloc(strlen(tmp) + 1, sizeof(char));
+ hdrdef = strdup(tmp);
if (hdrdef) {
- strcpy(hdrdef, tmp);
tmp = hdrdef;
while (*tmp) {
if (islower(*tmp))
@@ -1099,8 +1098,10 @@ XkbWriteCFile(FILE *out, char *name, XkbFileInfo *result)
fprintf(out, "#endif\n");
fprintf(out, "#define NUM_KEYS %d\n", xkb->max_key_code + 1);
ok = (*func) (out, result);
- if (hdrdef)
+ if (hdrdef) {
fprintf(out, "#endif /* %s */\n", hdrdef);
+ free(hdrdef);
+ }
}
if (!ok) {