kwo pushed a commit to branch master.

http://git.enlightenment.org/legacy/imlib2.git/commit/?id=90c5f5a26a8551699c2847dfcaee4dab552f7aca

commit 90c5f5a26a8551699c2847dfcaee4dab552f7aca
Author: Kim Woelders <k...@woelders.dk>
Date:   Sat Apr 10 04:16:28 2021 +0200

    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
---
 src/lib/context.c | 11 ++++++++---
 1 file 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;
 }
 

-- 


Reply via email to