gdiplus: Don't try to free invalid or already-freed images.
This commit is contained in:
parent
daa9d700de
commit
9326fc13ca
|
@ -1958,8 +1958,6 @@ GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
|
|||
if(!image)
|
||||
return InvalidParameter;
|
||||
|
||||
if (image->picture)
|
||||
IPicture_Release(image->picture);
|
||||
if (image->type == ImageTypeBitmap)
|
||||
{
|
||||
GdipFree(((GpBitmap*)image)->bitmapbits);
|
||||
|
@ -1967,7 +1965,15 @@ GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
|
|||
DeleteDC(((GpBitmap*)image)->hdc);
|
||||
DeleteObject(((GpBitmap*)image)->hbitmap);
|
||||
}
|
||||
else if (image->type != ImageTypeMetafile)
|
||||
{
|
||||
WARN("invalid image: %p\n", image);
|
||||
return ObjectBusy;
|
||||
}
|
||||
if (image->picture)
|
||||
IPicture_Release(image->picture);
|
||||
GdipFree(image->palette_entries);
|
||||
image->type = ~0;
|
||||
GdipFree(image);
|
||||
|
||||
return Ok;
|
||||
|
|
|
@ -2250,6 +2250,29 @@ static void test_colorkey(void)
|
|||
GdipDisposeImageAttributes(imageattr);
|
||||
}
|
||||
|
||||
static void test_dispose(void)
|
||||
{
|
||||
GpStatus stat;
|
||||
GpImage *image;
|
||||
char invalid_image[256];
|
||||
|
||||
stat = GdipDisposeImage(NULL);
|
||||
expect(InvalidParameter, stat);
|
||||
|
||||
stat = GdipCreateBitmapFromScan0(2, 2, 0, PixelFormat32bppARGB, NULL, (GpBitmap**)&image);
|
||||
expect(Ok, stat);
|
||||
|
||||
stat = GdipDisposeImage(image);
|
||||
expect(Ok, stat);
|
||||
|
||||
stat = GdipDisposeImage(image);
|
||||
expect(ObjectBusy, stat);
|
||||
|
||||
memset(invalid_image, 0, 256);
|
||||
stat = GdipDisposeImage((GpImage*)invalid_image);
|
||||
expect(ObjectBusy, stat);
|
||||
}
|
||||
|
||||
START_TEST(image)
|
||||
{
|
||||
struct GdiplusStartupInput gdiplusStartupInput;
|
||||
|
@ -2289,6 +2312,7 @@ START_TEST(image)
|
|||
test_rotateflip();
|
||||
test_remaptable();
|
||||
test_colorkey();
|
||||
test_dispose();
|
||||
|
||||
GdiplusShutdown(gdiplusToken);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue