Fix pixmap double-frees on error paths.

If AddResource fails, it will automatically free the object that was
passed to it by calling the appropriate deleteFunc; and of course
FreeResource also calls the deleteFunc. In both cases it's wrong to call
the destroy hook manually.

Commit by Jamey Sharp and Josh Triplett.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Aaron Plattner <aplattner@nvidia.com>
This commit is contained in:
Jamey Sharp 2010-09-14 18:35:21 -07:00
parent 8f69c935f6
commit 0f380a5005
2 changed files with 1 additions and 6 deletions

View File

@ -991,7 +991,6 @@ CreatePmap:
pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
pMap->drawable.id = newPix->info[j].id;
if (!AddResource(newPix->info[j].id, RT_PIXMAP, (pointer)pMap)) {
(*pScreen->DestroyPixmap)(pMap);
result = BadAlloc;
break;
}
@ -1002,10 +1001,8 @@ CreatePmap:
}
if(result == BadAlloc) {
while(j--) {
(*pScreen->DestroyPixmap)(pMap);
while(j--)
FreeResource(newPix->info[j].id, RT_NONE);
}
free(newPix);
} else
AddResource(stuff->pid, XRT_PIXMAP, newPix);
@ -1110,7 +1107,6 @@ CreatePmap:
{
return Success;
}
pDraw->pScreen->DestroyPixmap(pMap);
}
return BadAlloc;
}

View File

@ -1419,7 +1419,6 @@ CreatePmap:
}
if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap))
return Success;
(*pDraw->pScreen->DestroyPixmap)(pMap);
}
return BadAlloc;
}