mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 11:19:26 +02:00
Merge branch 'gtk2-fix-listview-images-doublefree' into 'main'
LCL-GTK2: Fix double free in listview pixbuf due to wrong refcounting See merge request freepascal.org/lazarus/lazarus!243
This commit is contained in:
commit
606baf0a8b
@ -445,8 +445,12 @@ var
|
||||
ImageList: TCustomImageList;
|
||||
Bmp: TBitmap;
|
||||
pixbuf: PGdkPixbuf;
|
||||
PixbufValue: TGValue;
|
||||
begin
|
||||
PGtkCellRendererPixbuf(cell)^.pixbuf := nil;
|
||||
PixbufValue:=Default(TGValue);
|
||||
g_value_init(@PixbufValue, GDK_TYPE_PIXBUF);
|
||||
g_object_set_property(G_OBJECT(cell), PChar('pixbuf'), @PixbufValue);
|
||||
g_value_unset(@PixbufValue);
|
||||
Widgets := PTVWidgets(WidgetInfo^.UserData);
|
||||
gtk_tree_model_get(tree_model, iter, [0, @ListItem, -1]);
|
||||
|
||||
@ -488,15 +492,19 @@ begin
|
||||
pixbuf := nil;
|
||||
ImageList.GetBitmap(ImageIndex, Bmp);
|
||||
Gtk2_PixBufFromBitmap(Bmp,pixbuf);
|
||||
PGtkCellRendererPixbuf(cell)^.pixbuf :=pixbuf;
|
||||
g_value_init(@PixbufValue, GDK_TYPE_PIXBUF);
|
||||
g_value_set_object(@PixbufValue, pixbuf);
|
||||
g_object_set_property(G_OBJECT(cell), PChar('pixbuf'), @PixbufValue);
|
||||
g_value_unset(@PixbufValue);
|
||||
finally
|
||||
Bmp.Free;
|
||||
end;
|
||||
end else
|
||||
if (ImageIndex > -1) and (ImageIndex <= Images.Count-1) then
|
||||
PGtkCellRendererPixbuf(cell)^.pixbuf := PGdkPixbuf(Images.Items[ImageIndex])
|
||||
else
|
||||
PGtkCellRendererPixbuf(cell)^.pixbuf := nil;
|
||||
g_value_init(@PixbufValue, GDK_TYPE_PIXBUF);
|
||||
if (ImageIndex > -1) and (ImageIndex <= Images.Count-1) and (Images.Items[ImageIndex] <> nil) then
|
||||
g_value_set_object(@PixbufValue, PGdkPixbuf(Images.Items[ImageIndex]));
|
||||
g_object_set_property(G_OBJECT(cell), PChar('pixbuf'), @PixbufValue);
|
||||
g_value_unset(@PixbufValue);
|
||||
end;
|
||||
|
||||
procedure Gtk2WSLV_ListViewGetPixbufDataFuncForIconView({%H-}cell_layout:PGtkCellLayout;
|
||||
@ -507,8 +515,12 @@ var
|
||||
Widgets: PTVWidgets;
|
||||
ImageIndex: Integer;
|
||||
APath: PGtkTreePath;
|
||||
PixbufValue: TGValue;
|
||||
begin
|
||||
PGtkCellRendererPixbuf(cell)^.pixbuf := nil;
|
||||
PixbufValue:=Default(TGValue);
|
||||
g_value_init(@PixbufValue, GDK_TYPE_PIXBUF);
|
||||
g_object_set_property(G_OBJECT(cell), 'pixbuf', @PixbufValue);
|
||||
g_value_unset(@PixbufValue);
|
||||
Widgets := PTVWidgets(WidgetInfo^.UserData);
|
||||
gtk_tree_model_get(tree_model, iter, [0, @ListItem, -1]);
|
||||
|
||||
@ -529,10 +541,11 @@ begin
|
||||
|
||||
ImageIndex := ListItem.ImageIndex;
|
||||
|
||||
g_value_init(@PixbufValue, GDK_TYPE_PIXBUF);
|
||||
if (ImageIndex > -1) and (ImageIndex <= Images.Count-1) then
|
||||
PGtkCellRendererPixbuf(cell)^.pixbuf := PGdkPixbuf(Images.Items[ImageIndex])
|
||||
else
|
||||
PGtkCellRendererPixbuf(cell)^.pixbuf := nil;
|
||||
g_value_set_object(@PixbufValue, PGdkPixbuf(Images.Items[ImageIndex]));
|
||||
g_object_set_property(G_OBJECT(cell), PChar('pixbuf'), @PixbufValue);
|
||||
g_value_unset(@PixbufValue);
|
||||
end;
|
||||
|
||||
{ TGtk2WSCustomListView }
|
||||
|
Loading…
Reference in New Issue
Block a user