diff options
author | Kim Woelders <kim@woelders.dk> | 2021-04-10 04:16:28 +0200 |
---|---|---|
committer | Kim Woelders <kim@woelders.dk> | 2021-04-13 06:56:32 +0200 |
commit | 90c5f5a26a8551699c2847dfcaee4dab552f7aca (patch) | |
tree | a27b03501dc56cff635ae25e64869ffe77375a6d | |
parent | bdbea7b38447928f74cfbd63ab75a30650eea8f1 (diff) | |
download | imlib2-90c5f5a26a8551699c2847dfcaee4dab552f7aca.tar.gz |
context.c: Fix potential segv
Also call __imlib_FlushContexts() before adding new context, not after
- It's pointless to check the new context
- Avoids (bogus) clang-analyzer warning
-rw-r--r-- | src/lib/context.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/lib/context.c b/src/lib/context.c index 351c077..6c4f4e1 100644 --- a/src/lib/context.c +++ b/src/lib/context.c @@ -39,9 +39,10 @@ __imlib_FlushContexts(void) if (ctt->last_use < (context_counter - max_context_count)) { if (pct) - context = ctt->next; - else pct->next = ctt->next; + else + context = ctt->next; + if (ctt->palette) { int i, num[] = { 256, 128, 64, 32, 16, 8, 1 }; @@ -140,6 +141,7 @@ __imlib_NewContext(Display * d, Visual * v, Colormap c, int depth) (void *)ct->b_dither, depth, 0); } } + return ct; } @@ -154,10 +156,13 @@ __imlib_GetContext(Display * d, Visual * v, Colormap c, int depth) ct->last_use = context_counter; return ct; } + + __imlib_FlushContexts(); + ct = __imlib_NewContext(d, v, c, depth); ct->next = context; context = ct; - __imlib_FlushContexts(); + return ct; } |