summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-12-11 09:22:57 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-01-03 11:02:11 -0800
commit4119707089b5c14f53bd5ff0b86ee7e575ac9316 (patch)
tree20d427c8efb2bb88c66826de30f70136274541a0
parent0d22aac7bb50ff1f7588f78ec25e9fb62a7b2e5e (diff)
downloadxorg-app-xkbcomp-4119707089b5c14f53bd5ff0b86ee7e575ac9316.tar.gz
XkbAddDirectoryToPath: don't leak existing paths on realloc() failure
Found by cppcheck: xkbpath.c:217:9: error: Common realloc mistake: 'includePath' nulled but not freed upon failure [memleakOnRealloc] includePath = (char **) realloc(includePath, szPath * sizeof(char *)); ^ Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--xkbpath.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/xkbpath.c b/xkbpath.c
index 695c13e..b5405de 100644
--- a/xkbpath.c
+++ b/xkbpath.c
@@ -213,13 +213,16 @@ XkbAddDirectoryToPath(const char *dir)
}
if (nPathEntries >= szPath)
{
+ char **new;
szPath += PATH_CHUNK;
- includePath = (char **) realloc(includePath, szPath * sizeof(char *));
- if (includePath == NULL)
+ new = (char **) realloc(includePath, szPath * sizeof(char *));
+ if (new == NULL)
{
WSGO("Allocation failed (includePath)\n");
return False;
}
+ else
+ includePath = new;
}
includePath[nPathEntries] =
(char *) calloc(strlen(dir) + 1, sizeof(char));