From 9828fd2c18b10cfd8d0edbc7b06a4f143efa7992 Mon Sep 17 00:00:00 2001 From: neil Date: Mon, 18 May 2015 00:54:09 +0000 Subject: [PATCH] - Fixed potential memory leaks and use of freed memory. - Reverted clearing of memory allocated through the Gallium WinSys API. It caused dramatically lower frame rates, at least in MESA demos. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@50703 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- workbench/devs/monitors/IntelGMA/aros_winsys.c | 15 +++++++++------ workbench/devs/monitors/IntelGMA/intelG45_init.c | 5 +++-- workbench/devs/monitors/IntelGMA/intelG45_lowlevel.c | 4 ++-- workbench/devs/monitors/IntelGMA/intelG45_memory.c | 3 ++- workbench/devs/monitors/IntelGMA/startup.c | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/workbench/devs/monitors/IntelGMA/aros_winsys.c b/workbench/devs/monitors/IntelGMA/aros_winsys.c index 76dfb491ec..f38421f061 100644 --- a/workbench/devs/monitors/IntelGMA/aros_winsys.c +++ b/workbench/devs/monitors/IntelGMA/aros_winsys.c @@ -105,7 +105,7 @@ VOID set_status(ULONG i,ULONG v) #endif } -APTR alloc_gfx_mem(ULONG size) +static APTR alloc_gfx_mem(ULONG size) { APTR result; @@ -128,7 +128,6 @@ APTR alloc_gfx_mem(ULONG size) if(result) { - memset(result, 0, size); allocated_mem+=size; D(bug("[GMA winsys] alloc_gfx_mem(%d) = %p allocated_mem %d\n", size, result, allocated_mem)); @@ -137,7 +136,7 @@ APTR alloc_gfx_mem(ULONG size) return result; } -VOID free_gfx_mem(APTR ptr, ULONG size) +static VOID free_gfx_mem(APTR ptr, ULONG size) { #ifdef GALLIUM_SIMULATION free(ptr);return; @@ -150,7 +149,8 @@ VOID free_gfx_mem(APTR ptr, ULONG size) VOID init_aros_winsys() { - // clean hw_status table,reserve first 100,( 0-15 is reserved,and bitmapclass uses at least 16-20) + // clean hw_status table, reserve first 100, (0-15 is reserved, and + // bitmapclass uses at least 16-20) int i; for(i=100;i<1024;i++) { @@ -384,8 +384,8 @@ void batchbuffer_destroy(struct i915_winsys_batchbuffer *ibatch) (bug("[GMA winsys] batchbuffer_destroy %p\n",ibatch)); struct aros_batchbuffer *batch = aros_batchbuffer(ibatch); FREE(ibatch->map); - FREE(batch); free_gfx_mem(batch->allocated_map, batch->allocated_size); + FREE(batch); LOCK_HW DO_FLUSH(); @@ -467,7 +467,7 @@ struct i915_winsys_buffer * { if( ! buffer_is_busy(0, buf ) ) { - D(bug("[GMA winsys] buffer_create: cheap seconhand buffer found:%p\n",buf);) + D(bug("[GMA winsys] buffer_create: cheap secondhand buffer found:%p\n", buf)); Remove((struct Node *)buf); ReleaseSemaphore(&UnusedBuffersListLock); return buf; @@ -485,7 +485,10 @@ struct i915_winsys_buffer * // allocate page aligned gfx memory buf->allocated_size = size + 4096; if( !(buf->allocated_map = alloc_gfx_mem(buf->allocated_size) ) ) + { + FREE(buf); return NULL; + } buf->map = (APTR)(((IPTR)buf->allocated_map + 4095)& ~4095); buf->size = size; buf->magic = MAGIC; diff --git a/workbench/devs/monitors/IntelGMA/intelG45_init.c b/workbench/devs/monitors/IntelGMA/intelG45_init.c index 8f79983c1c..c9ee35b4ae 100644 --- a/workbench/devs/monitors/IntelGMA/intelG45_init.c +++ b/workbench/devs/monitors/IntelGMA/intelG45_init.c @@ -263,7 +263,7 @@ AROS_UFH3(void, Enumerator, OOP_Object *driver; struct TagItem attrs[] = { - { aHidd_PCIDevice_isIO, TRUE }, /* Don't listen to IO transactions */ + { aHidd_PCIDevice_isIO, TRUE }, /* Listen to I/O transactions */ { aHidd_PCIDevice_isMEM, TRUE }, /* Listen to MEM transactions */ { aHidd_PCIDevice_isMaster, TRUE }, /* Can work in BusMaster */ { TAG_DONE, 0UL }, @@ -355,7 +355,8 @@ AROS_UFH3(void, Enumerator, sd->RingBufferSize = 64*4096; sd->RingBufferTail = 0; - /* Reserve some memory for HW cursor */ + /* Reserve some memory for HW cursor (this is also assumed to be 4kB + * aligned) */ sd->CursorImage = ((intptr_t)AllocGfxMem(sd, 64 * 64 * 4)) - (intptr_t)sd->Card.Framebuffer; if (NeedsPhysicalCursor(ProductID)) diff --git a/workbench/devs/monitors/IntelGMA/intelG45_lowlevel.c b/workbench/devs/monitors/IntelGMA/intelG45_lowlevel.c index 12ab190126..4818c4cdb3 100644 --- a/workbench/devs/monitors/IntelGMA/intelG45_lowlevel.c +++ b/workbench/devs/monitors/IntelGMA/intelG45_lowlevel.c @@ -554,8 +554,8 @@ IPTR AllocBitmapArea(struct g45staticdata *sd, ULONG width, ULONG height, width, height, bpp, result)); D(bug("[GMA] Available graphics memory is now %ldMB\n", sd->CardMem.mh_Free >> 20)); /* - If Allocate failed, make the 0xffffffff as return. If it succeeded, make - the memory pointer relative to the begin of GFX memory + If allocation failed, use -1 as return value. If it succeeded, + make the memory pointer relative to the beginning of GFX memory */ if (result == 0) result--; else result -= (IPTR)sd->Card.Framebuffer; diff --git a/workbench/devs/monitors/IntelGMA/intelG45_memory.c b/workbench/devs/monitors/IntelGMA/intelG45_memory.c index efdbb3152b..fe7c92557f 100644 --- a/workbench/devs/monitors/IntelGMA/intelG45_memory.c +++ b/workbench/devs/monitors/IntelGMA/intelG45_memory.c @@ -95,7 +95,7 @@ VOID FreeGfxMem(struct g45staticdata *sd, APTR ptr, ULONG size) } } - if(!freed) + if (!freed) header = (APTR)header->mh_Node.ln_Succ; } } @@ -192,6 +192,7 @@ void ReleaseGfxMemory(struct g45staticdata *sd, struct MemHeader *header) G45_DetachMemory(sd, (char *)header->mh_Lower - sd->Card.Framebuffer, header->mh_Free); FreeAlignedMem(header->mh_Node.ln_Name); + FreeVec(header); } static void G45_AttachMemory(struct g45staticdata *sd, intptr_t physical, diff --git a/workbench/devs/monitors/IntelGMA/startup.c b/workbench/devs/monitors/IntelGMA/startup.c index 800475757d..3143c69cfa 100644 --- a/workbench/devs/monitors/IntelGMA/startup.c +++ b/workbench/devs/monitors/IntelGMA/startup.c @@ -69,7 +69,7 @@ static const struct OOP_ABDescr attrbases[] = {NULL, NULL } }; -const TEXT version_string[] = "$VER: IntelGMA 3.10 (18.3.2015)\n"; +const TEXT version_string[] = "$VER: IntelGMA 3.11 (18.5.2015)\n"; extern struct WBStartup *WBenchMsg; int __nocommandline = 1; -- 2.11.4.GIT