[PATCH] Fix xf86DeleteDriver and various places that use it

christopher.halse.rogers at canonical.com christopher.halse.rogers at canonical.com
Sun Jul 21 20:44:46 PDT 2013


From: Maarten Lankhorst <maarten.lankhorst at canonical.com>

Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
---
 hw/xfree86/common/xf86Helper.c | 9 ++++++++-
 hw/xfree86/common/xf86Init.c   | 8 ++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 721159d..d319e0c 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -100,7 +100,14 @@ xf86DeleteDriver(int drvIndex)
         if (xf86DriverList[drvIndex]->module)
             UnloadModule(xf86DriverList[drvIndex]->module);
         free(xf86DriverList[drvIndex]);
-        xf86DriverList[drvIndex] = NULL;
+
+        /* Compact xf86DriverList array, update xf86NumDrivers */
+        xf86NumDrivers--;
+        if(drvIndex != xf86NumDrivers)
+            memmove(xf86DriverList + drvIndex,
+                    xf86DriverList + drvIndex + 1,
+                    sizeof(DriverPtr) * (xf86NumDrivers - drvIndex));
+        xf86DriverList = realloc(xf86DriverList, xf86NumDrivers * sizeof(DriverPtr));
     }
 }
 
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 91ec4c8..746168a 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -530,7 +530,7 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
          * needed at this early stage.
          */
 
-        for (i = 0; i < xf86NumDrivers; i++) {
+        for (i = 0; i < xf86NumDrivers; ) {
             xorgHWFlags flags = HW_IO;
 
             if (xf86DriverList[i]->Identify != NULL)
@@ -546,6 +546,8 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
 
             if (!(flags & HW_SKIP_CONSOLE))
                 xorgHWOpenConsole = TRUE;
+
+            i++;
         }
 
         if (xorgHWOpenConsole)
@@ -631,9 +633,11 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
         }
 
         /* Remove (unload) drivers that are not required */
-        for (i = 0; i < xf86NumDrivers; i++)
+        for (i = 0; i < xf86NumDrivers; )
             if (xf86DriverList[i] && xf86DriverList[i]->refCount <= 0)
                 xf86DeleteDriver(i);
+            else
+                i++;
 
         /*
          * At this stage we know how many screens there are.
-- 
1.8.3.2



More information about the xorg-devel mailing list