From 4119707089b5c14f53bd5ff0b86ee7e575ac9316 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 11 Dec 2022 09:22:57 -0800 Subject: 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 --- xkbpath.c | 7 +++++-- 1 file 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)); -- cgit v1.2.3