diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-03-18 12:22:34 +1000 |
---|---|---|
committer | Ran Benita <ran@unusedvar.com> | 2021-03-19 23:44:30 +0200 |
commit | 95e29079788a376c4b02d6c7f06ad8b447f3f935 (patch) | |
tree | 0f759210f244e4cfac4ddd89a1323bf613c7a54a /src | |
parent | 01aa2222576c88308d74bbc7f0c459d4acada681 (diff) | |
download | xorg-lib-libxkbcommon-95e29079788a376c4b02d6c7f06ad8b447f3f935.tar.gz |
xkbcomp: plug a potential memory leak
libxkbcommon-1.0.3/src/xkbcomp/ast-build.c:526: leaked_storage: Variable "file"
going out of scope leaks the storage it points to.
Where we exit the loop early, we don't release the various allocated memory.
Make this patch more obvious my moving the declaration for those into the loop
as well, this way we know that they aren't used outside the loop anywhere.
Found by coverity
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/xkbcomp/ast-build.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/xkbcomp/ast-build.c b/src/xkbcomp/ast-build.c index 7ee13d0..347eed8 100644 --- a/src/xkbcomp/ast-build.c +++ b/src/xkbcomp/ast-build.c @@ -462,15 +462,16 @@ IncludeStmt * IncludeCreate(struct xkb_context *ctx, char *str, enum merge_mode merge) { IncludeStmt *incl, *first; - char *file, *map, *stmt, *tmp, *extra_data; + char *stmt, *tmp; char nextop; incl = first = NULL; - file = map = NULL; tmp = str; stmt = strdup_safe(str); while (tmp && *tmp) { + char *file = NULL, *map = NULL, *extra_data = NULL; + if (!ParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data)) goto err; @@ -494,8 +495,12 @@ IncludeCreate(struct xkb_context *ctx, char *str, enum merge_mode merge) incl = incl->next_incl; } - if (!incl) + if (!incl) { + free(file); + free(map); + free(extra_data); break; + } incl->common.type = STMT_INCLUDE; incl->common.next = NULL; |