Qt,Qt5,Qt6: fixed multiple memleaks with QIcon. issue #41497

This commit is contained in:
zeljan1 2025-03-01 16:35:55 +01:00
parent 15a32b17fc
commit 9d39dd3e25
9 changed files with 106 additions and 36 deletions

View File

@ -125,7 +125,9 @@ begin
Size.cy := Res.Height;
QTabWidget_setIconSize(TQtPage(ACustomPage.Handle).getTabWidget, @Size);
end;
TQtPage(ACustomPage.Handle).setIcon(TQtImage(Bmp.Handle).AsIcon);
Icon := TQtImage(Bmp.Handle).AsIcon;
TQtPage(ACustomPage.Handle).setIcon(Icon);
QIcon_destroy(Icon);
B := True;
finally
Bmp.Free;

View File

@ -12450,7 +12450,9 @@ begin
v2 := QVariant_create(AImageIndex);
QListWidgetItem_setData(item, QtListViewOwnerDataRole, v2);
QVariant_destroy(v2);
QListWidgetItem_setIcon(item, TQtImage(Bmp.Handle).AsIcon)
AIcon := TQtImage(Bmp.Handle).AsIcon;
QListWidgetItem_setIcon(item, AIcon);
QIcon_destroy(AIcon);
end;
// else we are imageIndex and that''s fine.
end else
@ -12458,7 +12460,9 @@ begin
v2 := QVariant_create(AImageIndex);
QListWidgetItem_setData(item, QtListViewOwnerDataRole, v2);
QVariant_destroy(v2);
QListWidgetItem_setIcon(item, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QListWidgetItem_setIcon(item, AIcon);
QIcon_destroy(AIcon);
end;
finally
Bmp.Free;
@ -14676,7 +14680,9 @@ begin
v2 := QVariant_create(AImageIndex);
QTreeWidgetItem_setData(item, 0, QtListViewOwnerDataRole, v2);
QVariant_destroy(v2);
QTreeWidgetItem_setIcon(item, 0, TQtImage(Bmp.Handle).AsIcon)
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(item, 0, AIcon);
QIcon_destroy(AIcon);
end;
// else we are imageIndex and that''s fine.
end else
@ -14684,7 +14690,9 @@ begin
v2 := QVariant_create(AImageIndex);
QTreeWidgetItem_setData(item, 0, QtListViewOwnerDataRole, v2);
QVariant_destroy(v2);
QTreeWidgetItem_setIcon(item, 0, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(item, 0, AIcon);
QIcon_destroy(AIcon);
end;
finally
Bmp.Free;

View File

@ -970,6 +970,7 @@ var
TWI: QTreeWidgetItemH;
Bmp: TBitmap;
ImgListRes: TScaledImageListResolution;
AIcon: QIconH;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetImage') then
Exit;
@ -989,7 +990,9 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AImageIndex, Bmp);
QTreeWidgetItem_setIcon(TWI, AIndex, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(TWI, AIndex, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
@ -1263,6 +1266,7 @@ var
TWI: QTreeWidgetItemH;
Bmp: TBitmap;
ImgListRes: TScaledImageListResolution;
AIcon: QIconH;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetImage') then
Exit;
@ -1293,10 +1297,12 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AImageIndex, Bmp);
AIcon := TQtImage(Bmp.Handle).AsIcon;
if LWI <> nil then
QListWidgetItem_setIcon(LWI, TQtImage(Bmp.Handle).AsIcon)
QListWidgetItem_setIcon(LWI, AIcon)
else
QTreeWidgetItem_setIcon(TWI, ASubIndex, TQtImage(Bmp.Handle).AsIcon);
QTreeWidgetItem_setIcon(TWI, ASubIndex, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
@ -1407,6 +1413,7 @@ var
ImgListRes: TScaledImageListResolution;
AImgList: TCustomImageList;
AImgListWidth: Integer;
AIcon: QIconH;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetStateImage') then
Exit;
@ -1438,10 +1445,12 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AStateImageIndex, Bmp);
AIcon := TQtImage(Bmp.Handle).AsIcon;
if LWI <> nil then
QListWidgetItem_setIcon(LWI, TQtImage(Bmp.Handle).AsIcon)
QListWidgetItem_setIcon(LWI, AIcon)
else
QTreeWidgetItem_setIcon(TWI, ASubIndex, TQtImage(Bmp.Handle).AsIcon);
QTreeWidgetItem_setIcon(TWI, ASubIndex, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
@ -2022,6 +2031,7 @@ var
AAlignment: QtAlignment;
Bmp: TBitmap;
ImgListRes: TScaledImageListResolution;
AIcon: QIconH;
begin
QtTreeWidget := TQtTreeWidget(AList.Handle);
@ -2057,7 +2067,9 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AItem.ImageIndex, Bmp);
QTreeWidgetItem_setIcon(Item, 0, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(Item, 0, AIcon);
QIcon_Destroy(AIcon);
finally
Bmp.Free;
end;
@ -2078,7 +2090,9 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AItem.SubItemImages[j], Bmp);
QTreeWidgetItem_setIcon(Item, j + 1, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(Item, j + 1, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;

View File

@ -126,7 +126,9 @@ begin
Size.cy := Res.Height;
QTabWidget_setIconSize(TQtPage(ACustomPage.Handle).getTabWidget, @Size);
end;
TQtPage(ACustomPage.Handle).setIcon(TQtImage(Bmp.Handle).AsIcon);
Icon := TQtImage(Bmp.Handle).AsIcon;
TQtPage(ACustomPage.Handle).setIcon(Icon);
QIcon_destroy(Icon);
B := True;
finally
Bmp.Free;

View File

@ -12873,7 +12873,9 @@ begin
v2 := QVariant_create(AImageIndex);
QListWidgetItem_setData(item, QtListViewOwnerDataRole, v2);
QVariant_destroy(v2);
QListWidgetItem_setIcon(item, TQtImage(Bmp.Handle).AsIcon)
AIcon := TQtImage(Bmp.Handle).AsIcon;
QListWidgetItem_setIcon(item, AIcon);
QIcon_destroy(AIcon);
end;
// else we are imageIndex and that''s fine.
end else
@ -12881,7 +12883,9 @@ begin
v2 := QVariant_create(AImageIndex);
QListWidgetItem_setData(item, QtListViewOwnerDataRole, v2);
QVariant_destroy(v2);
QListWidgetItem_setIcon(item, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QListWidgetItem_setIcon(item, AIcon);
QIcon_destroy(AIcon);
end;
finally
Bmp.Free;
@ -15112,7 +15116,9 @@ begin
v2 := QVariant_create(AImageIndex);
QTreeWidgetItem_setData(item, 0, QtListViewOwnerDataRole, v2);
QVariant_destroy(v2);
QTreeWidgetItem_setIcon(item, 0, TQtImage(Bmp.Handle).AsIcon)
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(item, 0, AIcon);
QIcon_destroy(AIcon);
end;
// else we are imageIndex and that''s fine.
end else
@ -15120,7 +15126,9 @@ begin
v2 := QVariant_create(AImageIndex);
QTreeWidgetItem_setData(item, 0, QtListViewOwnerDataRole, v2);
QVariant_destroy(v2);
QTreeWidgetItem_setIcon(item, 0, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(item, 0, AIcon);
QIcon_destroy(AIcon);
end;
finally
Bmp.Free;

View File

@ -1019,6 +1019,7 @@ var
TWI: QTreeWidgetItemH;
Bmp: TBitmap;
ImgListRes: TScaledImageListResolution;
AIcon: QIconH;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetImage') then
Exit;
@ -1038,7 +1039,9 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AImageIndex, Bmp);
QTreeWidgetItem_setIcon(TWI, AIndex, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(TWI, AIndex, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
@ -1354,10 +1357,12 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AImageIndex, Bmp);
AIcon := TQtImage(Bmp.Handle).AsIcon;
if LWI <> nil then
QListWidgetItem_setIcon(LWI, TQtImage(Bmp.Handle).AsIcon)
QListWidgetItem_setIcon(LWI, AIcon)
else
QTreeWidgetItem_setIcon(TWI, ASubIndex, TQtImage(Bmp.Handle).AsIcon);
QTreeWidgetItem_setIcon(TWI, ASubIndex, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
@ -1475,6 +1480,7 @@ var
ImgListRes: TScaledImageListResolution;
AImgList: TCustomImageList;
AImgListWidth: Integer;
AIcon: QIconH;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetStateImage') then
Exit;
@ -1506,10 +1512,12 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AStateImageIndex, Bmp);
AIcon := TQtImage(Bmp.Handle).AsIcon;
if LWI <> nil then
QListWidgetItem_setIcon(LWI, TQtImage(Bmp.Handle).AsIcon)
QListWidgetItem_setIcon(LWI, AIcon)
else
QTreeWidgetItem_setIcon(TWI, ASubIndex, TQtImage(Bmp.Handle).AsIcon);
QTreeWidgetItem_setIcon(TWI, ASubIndex, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
@ -2095,6 +2103,7 @@ var
AAlignment: QtAlignment;
Bmp: TBitmap;
ImgListRes: TScaledImageListResolution;
AIcon: QIconH;
begin
QtTreeWidget := TQtTreeWidget(AList.Handle);
@ -2130,7 +2139,9 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AItem.ImageIndex, Bmp);
QTreeWidgetItem_setIcon(Item, 0, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(Item, 0, AIcon);
QIcon_Destroy(AIcon);
finally
Bmp.Free;
end;
@ -2151,7 +2162,9 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AItem.SubItemImages[j], Bmp);
QTreeWidgetItem_setIcon(Item, j + 1, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(Item, j + 1, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;

View File

@ -126,7 +126,9 @@ begin
Size.cy := Res.Height;
QTabWidget_setIconSize(TQtPage(ACustomPage.Handle).getTabWidget, @Size);
end;
TQtPage(ACustomPage.Handle).setIcon(TQtImage(Bmp.Handle).AsIcon);
Icon := TQtImage(Bmp.Handle).AsIcon;
TQtPage(ACustomPage.Handle).setIcon(Icon);
QIcon_destroy(Icon);
B := True;
finally
Bmp.Free;

View File

@ -12791,7 +12791,9 @@ begin
v2 := QVariant_create(AImageIndex);
QListWidgetItem_setData(item, QtListViewOwnerDataRole, v2);
QVariant_destroy(v2);
QListWidgetItem_setIcon(item, TQtImage(Bmp.Handle).AsIcon)
AIcon := TQtImage(Bmp.Handle).AsIcon;
QListWidgetItem_setIcon(item, AIcon);
QIcon_destroy(AIcon);
end;
// else we are imageIndex and that''s fine.
end else
@ -12799,7 +12801,9 @@ begin
v2 := QVariant_create(AImageIndex);
QListWidgetItem_setData(item, QtListViewOwnerDataRole, v2);
QVariant_destroy(v2);
QListWidgetItem_setIcon(item, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QListWidgetItem_setIcon(item, AIcon);
QIcon_destroy(AIcon);
end;
finally
Bmp.Free;
@ -15031,7 +15035,9 @@ begin
v2 := QVariant_create(AImageIndex);
QTreeWidgetItem_setData(item, 0, QtListViewOwnerDataRole, v2);
QVariant_destroy(v2);
QTreeWidgetItem_setIcon(item, 0, TQtImage(Bmp.Handle).AsIcon)
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(item, 0, AIcon);
QIcon_destroy(AIcon);
end;
// else we are imageIndex and that''s fine.
end else
@ -15039,7 +15045,9 @@ begin
v2 := QVariant_create(AImageIndex);
QTreeWidgetItem_setData(item, 0, QtListViewOwnerDataRole, v2);
QVariant_destroy(v2);
QTreeWidgetItem_setIcon(item, 0, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(item, 0, AIcon);
QIcon_destroy(AIcon);
end;
finally
Bmp.Free;

View File

@ -1018,6 +1018,7 @@ var
TWI: QTreeWidgetItemH;
Bmp: TBitmap;
ImgListRes: TScaledImageListResolution;
AIcon: QIconH;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetImage') then
Exit;
@ -1037,7 +1038,9 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AImageIndex, Bmp);
QTreeWidgetItem_setIcon(TWI, AIndex, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(TWI, AIndex, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
@ -1353,10 +1356,12 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AImageIndex, Bmp);
AIcon := TQtImage(Bmp.Handle).AsIcon;
if LWI <> nil then
QListWidgetItem_setIcon(LWI, TQtImage(Bmp.Handle).AsIcon)
QListWidgetItem_setIcon(LWI, AIcon)
else
QTreeWidgetItem_setIcon(TWI, ASubIndex, TQtImage(Bmp.Handle).AsIcon);
QTreeWidgetItem_setIcon(TWI, ASubIndex, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
@ -1474,6 +1479,7 @@ var
ImgListRes: TScaledImageListResolution;
AImgList: TCustomImageList;
AImgListWidth: Integer;
AIcon: QIconH;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetStateImage') then
Exit;
@ -1505,10 +1511,12 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AStateImageIndex, Bmp);
AIcon := TQtImage(Bmp.Handle).AsIcon;
if LWI <> nil then
QListWidgetItem_setIcon(LWI, TQtImage(Bmp.Handle).AsIcon)
QListWidgetItem_setIcon(LWI, AIcon)
else
QTreeWidgetItem_setIcon(TWI, ASubIndex, TQtImage(Bmp.Handle).AsIcon);
QTreeWidgetItem_setIcon(TWI, ASubIndex, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;
@ -2094,6 +2102,7 @@ var
AAlignment: QtAlignment;
Bmp: TBitmap;
ImgListRes: TScaledImageListResolution;
AIcon: QIconH;
begin
QtTreeWidget := TQtTreeWidget(AList.Handle);
@ -2129,7 +2138,9 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AItem.ImageIndex, Bmp);
QTreeWidgetItem_setIcon(Item, 0, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(Item, 0, AIcon);
QIcon_Destroy(AIcon);
finally
Bmp.Free;
end;
@ -2150,7 +2161,9 @@ begin
Bmp := TBitmap.Create;
try
ImgListRes.GetBitmap(AItem.SubItemImages[j], Bmp);
QTreeWidgetItem_setIcon(Item, j + 1, TQtImage(Bmp.Handle).AsIcon);
AIcon := TQtImage(Bmp.Handle).AsIcon;
QTreeWidgetItem_setIcon(Item, j + 1, AIcon);
QIcon_destroy(AIcon);
finally
Bmp.Free;
end;