diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-12-11 09:22:57 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-01-03 11:02:11 -0800 |
commit | 4119707089b5c14f53bd5ff0b86ee7e575ac9316 (patch) | |
tree | 20d427c8efb2bb88c66826de30f70136274541a0 | |
parent | 0d22aac7bb50ff1f7588f78ec25e9fb62a7b2e5e (diff) |
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.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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)); |