libhwc: fix potential crash when checking on update_stat_thread status
authorDanny Wood <danwood76@gmail.com>
Thu, 20 Feb 2020 19:44:56 +0000 (19:44 +0000)
committerJan Altensen <info@stricted.net>
Wed, 8 Apr 2020 10:53:15 +0000 (12:53 +0200)
Change-Id: I9060a57628c916c0b1b7a96dedf2286be2bd8475

libhwc/ExynosHWC.cpp

index 30e1a2213381ea3f1158d99322a4af576c8f25d4..21d739710ca9f32cb87b6546f77f1c24a556444e 100644 (file)
@@ -734,10 +734,13 @@ int exynos5_blank(struct hwc_composer_device_1 *dev, int disp, int blank)
 #endif
         pdev->primaryDisplay->mBlanked = !!blank;
 
-        if (pthread_kill(pdev->update_stat_thread, 0) != ESRCH) { //check if the thread is alive
-           if (fb_blank == FB_BLANK_POWERDOWN) {
-                pdev->update_stat_thread_flag = false;
-                pthread_join(pdev->update_stat_thread, 0);
+        /* Check if the thread is enabled before calling pthread_kill as we will seg fault otherwise */
+        if(pdev->update_stat_thread_flag == true) {
+            if (pthread_kill(pdev->update_stat_thread, 0) != ESRCH) { //check if the thread is alive
+               if (fb_blank == FB_BLANK_POWERDOWN) {
+                    pdev->update_stat_thread_flag = false;
+                    pthread_join(pdev->update_stat_thread, 0);
+                }
             }
         } else { // thread is not alive
             if (fb_blank == FB_BLANK_UNBLANK && pdev->hwc_ctrl.dynamic_recomp_mode == true)
@@ -1111,10 +1114,13 @@ int exynos_setPowerMode(struct hwc_composer_device_1* dev, int disp, int mode)
 #endif
         pdev->primaryDisplay->mBlanked = !!blank;
 
-        if (pthread_kill(pdev->update_stat_thread, 0) != ESRCH) { //check if the thread is alive
-           if (fb_blank == FB_BLANK_POWERDOWN) {
-                pdev->update_stat_thread_flag = false;
-                pthread_join(pdev->update_stat_thread, 0);
+        /* Check if the thread is enabled before calling pthread_kill as we will seg fault otherwise */
+        if(pdev->update_stat_thread_flag == true) {
+            if (pthread_kill(pdev->update_stat_thread, 0) != ESRCH) { //check if the thread is alive
+               if (fb_blank == FB_BLANK_POWERDOWN) {
+                    pdev->update_stat_thread_flag = false;
+                    pthread_join(pdev->update_stat_thread, 0);
+                }
             }
         } else { // thread is not alive
             if (fb_blank == FB_BLANK_UNBLANK && pdev->hwc_ctrl.dynamic_recomp_mode == true)