summaryrefslogtreecommitdiff
path: root/src/stubs/atom.c
diff options
context:
space:
mode:
authorJosé Expósito <jexposit@redhat.com>2024-07-01 16:28:04 +0200
committerJosé Expósito <jexposit@redhat.com>2024-07-01 16:28:12 +0200
commit0006737243ee3599775e41b59c42028e07a68f0a (patch)
tree7925b3dbd65d6da4dab6cfa5c741f677fbd004f2 /src/stubs/atom.c
parentc47d610ae27e89911539773f15bd7940fc00d35d (diff)
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: <https://gitlab.freedesktop.org/xorg/lib/libxfont/-/merge_requests/27>
Diffstat (limited to 'src/stubs/atom.c')
-rw-r--r--src/stubs/atom.c4
1 files changed, 3 insertions, 1 deletions
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;