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)
|
if(!image)
|
||||||
return InvalidParameter;
|
return InvalidParameter;
|
||||||
|
|
||||||
if (image->picture)
|
|
||||||
IPicture_Release(image->picture);
|
|
||||||
if (image->type == ImageTypeBitmap)
|
if (image->type == ImageTypeBitmap)
|
||||||
{
|
{
|
||||||
GdipFree(((GpBitmap*)image)->bitmapbits);
|
GdipFree(((GpBitmap*)image)->bitmapbits);
|
||||||
|
@ -1967,7 +1965,15 @@ GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
|
||||||
DeleteDC(((GpBitmap*)image)->hdc);
|
DeleteDC(((GpBitmap*)image)->hdc);
|
||||||
DeleteObject(((GpBitmap*)image)->hbitmap);
|
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);
|
GdipFree(image->palette_entries);
|
||||||
|
image->type = ~0;
|
||||||
GdipFree(image);
|
GdipFree(image);
|
||||||
|
|
||||||
return Ok;
|
return Ok;
|
||||||
|
|
|
@ -2250,6 +2250,29 @@ static void test_colorkey(void)
|
||||||
GdipDisposeImageAttributes(imageattr);
|
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)
|
START_TEST(image)
|
||||||
{
|
{
|
||||||
struct GdiplusStartupInput gdiplusStartupInput;
|
struct GdiplusStartupInput gdiplusStartupInput;
|
||||||
|
@ -2289,6 +2312,7 @@ START_TEST(image)
|
||||||
test_rotateflip();
|
test_rotateflip();
|
||||||
test_remaptable();
|
test_remaptable();
|
||||||
test_colorkey();
|
test_colorkey();
|
||||||
|
test_dispose();
|
||||||
|
|
||||||
GdiplusShutdown(gdiplusToken);
|
GdiplusShutdown(gdiplusToken);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue