From 0006737243ee3599775e41b59c42028e07a68f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Mon, 1 Jul 2024 16:28:04 +0200 Subject: stubs/atom.c: Fix memory leak in __libxfont_internal__MakeAtom Reported by a static analysis tool: 9. libXfont2-2.0.6/src/stubs/atom.c:179:5: alloc_fn: Storage is returned from allocation function "malloc". 10. libXfont2-2.0.6/src/stubs/atom.c:179:5: var_assign: Assigning: "a" = storage returned from "malloc(24UL + len + 1UL)". 16. libXfont2-2.0.6/src/stubs/atom.c:194:6: leaked_storage: Variable "a" going out of scope leaks the storage it points to. # 192| if ((ResizeHashTable() == FALSE) && # 193| ((hashTable == NULL) || (hashUsed == hashSize))) # 194|-> return None; # 195| h = hash & hashMask; # 196| if (hashTable[h]) { Fixes: 78085e6b683b ("stubs/atom.c: check for ResizeHashTable failure") Part-of: --- src/stubs/atom.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/stubs/atom.c b/src/stubs/atom.c index 367ddc9..4163ee7 100644 --- a/src/stubs/atom.c +++ b/src/stubs/atom.c @@ -188,8 +188,10 @@ __libxfont_internal__MakeAtom(const char *string, unsigned len, int makeit) a->hash = hash; if (hashUsed >= hashSize / 2) { if ((ResizeHashTable() == FALSE) && - ((hashTable == NULL) || (hashUsed == hashSize))) + ((hashTable == NULL) || (hashUsed == hashSize))) { + free(a); return None; + } h = hash & hashMask; if (hashTable[h]) { r = (hash % rehash) | 1; -- cgit v1.2.3