diff options
author | Matthieu Herrb <matthieu.herrb@laas.fr> | 2012-04-02 08:22:23 +0200 |
---|---|---|
committer | Matthieu Herrb <matthieu.herrb@laas.fr> | 2012-04-04 08:12:10 +0200 |
commit | 6f9d9f1e1b093939bc459be606fba72f1d6dfc76 (patch) | |
tree | 7de0194b9468ac6dc500bc032394ab347d11fc83 | |
parent | 725f5669bc03ed9a766e2c51c465e082172e6dae (diff) |
Fix pci_io_handle allocation routines.
The previous version of new_io_handle() would invalidate all previous
allocations when realloc moves the base pointer of the ios array.
Since I cannot figure out where this array is useful, just get rid of
it, providing sound stable memory allocation.
Fixes vgaHWSaveFonts() in 1.12 xserver on OpenBSD, but other
sub-systems relaying on pci_io could be affected too.
Signed-off-by: Matthieu Herrb <matthieu.herrb@laas.fr>
Tested-by: Tormod Volden <debian.tormod@gmail.com>
-rw-r--r-- | src/common_io.c | 39 |
1 files changed, 4 insertions, 35 deletions
diff --git a/src/common_io.c b/src/common_io.c index 5b35e07..f5c9e45 100644 --- a/src/common_io.c +++ b/src/common_io.c @@ -28,59 +28,28 @@ #include "pciaccess.h" #include "pciaccess_private.h" -static struct pci_io_handle *ios; -static unsigned int num_ios; - static struct pci_io_handle * new_io_handle(void) { struct pci_io_handle *new; - new = realloc(ios, sizeof(struct pci_io_handle) * (num_ios + 1)); + new = malloc(sizeof(struct pci_io_handle)); if (!new) return NULL; - ios = new; - num_ios++; - - return ios + num_ios - 1; + return new; } static void delete_io_handle(struct pci_io_handle *handle) { - struct pci_io_handle *new; - int i = 0; - - if (!handle || !num_ios || (void *)handle < (void *)ios || - (void *)handle > (void *)(ios + num_ios - 1)) - return; - - for (i = 0; i < num_ios; i++) { - if (ios + i == handle) { - memmove(&ios[i], &ios[i+1], sizeof(struct pci_io_handle) * - (num_ios - i - 1)); - break; - } - } - - num_ios--; - if (num_ios) { - new = realloc(ios, sizeof(struct pci_io_handle) * num_ios); - if (new) - ios = new; - } else { - free(ios); - ios = NULL; - } + free(handle); + return; } _pci_hidden void pci_io_cleanup(void) { - free(ios); - ios = NULL; - num_ios = 0; } /** |