diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2010-11-27 19:06:56 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2010-11-30 16:25:22 -0800 |
commit | 4bbc90cd8b7e749fd8072ce7cd8dd998f4396981 (patch) | |
tree | b50159c2f15ef2147e647dfbdf16a1f794fb85c1 | |
parent | 2c8e534c8e9334562485aeaaef374871cf14d5fe (diff) |
xf86AutoConfig: make copyScreen memory allocation & error handling more sane
No point calling the no-fail-alloc if you check for failure and your
only caller checks for failure.
No point calling calloc to zero fill memory you're about to memcpy over.
In the unlikely event of a loss of memory allocation, drop your previous
allocations before returning to others.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Julien Cristau <jcristau@debian.org>
Reviewed-by: Mikhail Gusarov <dottedmag@dottedmag.net>
-rw-r--r-- | hw/xfree86/common/xf86AutoConfig.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c index 200cb8f03..3cd5ef6ff 100644 --- a/hw/xfree86/common/xf86AutoConfig.c +++ b/hw/xfree86/common/xf86AutoConfig.c @@ -282,21 +282,31 @@ listPossibleVideoDrivers(char *matches[], int nmatches) static Bool copyScreen(confScreenPtr oscreen, GDevPtr odev, int i, char *driver) { + confScreenPtr nscreen; GDevPtr cptr = NULL; - xf86ConfigLayout.screens[i].screen = xnfcalloc(1, sizeof(confScreenRec)); - if(!xf86ConfigLayout.screens[i].screen) + nscreen = malloc(sizeof(confScreenRec)); + if (!nscreen) return FALSE; - memcpy(xf86ConfigLayout.screens[i].screen, oscreen, sizeof(confScreenRec)); + memcpy(nscreen, oscreen, sizeof(confScreenRec)); - cptr = calloc(1, sizeof(GDevRec)); - if (!cptr) + cptr = malloc(sizeof(GDevRec)); + if (!cptr) { + free(nscreen); return FALSE; + } memcpy(cptr, odev, sizeof(GDevRec)); cptr->identifier = Xprintf("Autoconfigured Video Device %s", driver); + if (!cptr->identifier) { + free(cptr); + free(nscreen); + return FALSE; + } cptr->driver = driver; + xf86ConfigLayout.screens[i].screen = nscreen; + /* now associate the new driver entry with the new screen entry */ xf86ConfigLayout.screens[i].screen->device = cptr; cptr->myScreenSection = xf86ConfigLayout.screens[i].screen; |