summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-04-10 04:16:28 +0200
committerKim Woelders <kim@woelders.dk>2021-04-13 06:56:32 +0200
commit90c5f5a26a8551699c2847dfcaee4dab552f7aca (patch)
treea27b03501dc56cff635ae25e64869ffe77375a6d
parentbdbea7b38447928f74cfbd63ab75a30650eea8f1 (diff)
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.c11
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)
39 if (ctt->last_use < (context_counter - max_context_count)) 39 if (ctt->last_use < (context_counter - max_context_count))
40 { 40 {
41 if (pct) 41 if (pct)
42 context = ctt->next;
43 else
44 pct->next = ctt->next; 42 pct->next = ctt->next;
43 else
44 context = ctt->next;
45
45 if (ctt->palette) 46 if (ctt->palette)
46 { 47 {
47 int i, num[] = { 256, 128, 64, 32, 16, 8, 1 }; 48 int i, num[] = { 256, 128, 64, 32, 16, 8, 1 };
@@ -140,6 +141,7 @@ __imlib_NewContext(Display * d, Visual * v, Colormap c, int depth)
140 (void *)ct->b_dither, depth, 0); 141 (void *)ct->b_dither, depth, 0);
141 } 142 }
142 } 143 }
144
143 return ct; 145 return ct;
144} 146}
145 147
@@ -154,10 +156,13 @@ __imlib_GetContext(Display * d, Visual * v, Colormap c, int depth)
154 ct->last_use = context_counter; 156 ct->last_use = context_counter;
155 return ct; 157 return ct;
156 } 158 }
159
160 __imlib_FlushContexts();
161
157 ct = __imlib_NewContext(d, v, c, depth); 162 ct = __imlib_NewContext(d, v, c, depth);
158 ct->next = context; 163 ct->next = context;
159 context = ct; 164 context = ct;
160 __imlib_FlushContexts(); 165
161 return ct; 166 return ct;
162} 167}
163 168