View Issue Details

IDProjectCategoryView StatusLast Update
0034795LazarusWidgetsetpublic2019-01-12 21:27
ReporterengkinAssigned ToJuha Manninen 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformOSLinux/WinOS Versionany
Product Version1.8.2Product Build 
Target VersionFixed in Version 
Summary0034795: [Patch] GTK2: Clipboard.AsText crashs sometimes.
DescriptionIn \lcl\interfaces\gtk2\gtk2winapi.inc file, Function TGtk2WidgetSet.ClipboardGetData: SupportedFormats gets the same address from SelData.Data:

      SupportedFormats:=PGdkAtom(SelData.Data);

at the end of ClipboardGetData both get freed:

      finally
        if SupportedFormats<>nil then FreeMem(SupportedFormats);
        if SelData.Data<>nil then FreeMem(SelData.Data); //<--- this may cause a crash
      end;
    end;

The attached patch
Steps To ReproduceDownload the project which I'll attach in a comment.
Compile and run after using GTK2 as the widgetset.
Copy any image from the forum and click the button labeled "Clipboard.AsText".
Additional InformationForum member dbannon (Davo) reported the issue here:
http://forum.lazarus.freepascal.org/index.php/topic,43750.0.html

He also provided a sample project which I'll include in this report in the first comment.
TagsNo tags attached.
Fixed in Revisionr60064
LazTarget-
WidgetsetGTK 2
Attached Files
  • patch.diff (450 bytes)
    Index: gtk2winapi.inc
    ===================================================================
    --- gtk2winapi.inc	(revision 59976)
    +++ gtk2winapi.inc	(working copy)
    @@ -432,7 +432,7 @@
         Result:=true;
       finally
         if SupportedFormats<>nil then FreeMem(SupportedFormats);
    -    if SelData.Data<>nil then FreeMem(SelData.Data);
    +    if (SelData.Data<>nil) and (PGdkAtom(SelData.Data)<>SupportedFormats) then FreeMem(SelData.Data);
       end;
     end;
     
    
    patch.diff (450 bytes)
  • ShowClipboard.zip (129,792 bytes)

Activities

engkin

2019-01-02 20:32

reporter  

patch.diff (450 bytes)
Index: gtk2winapi.inc
===================================================================
--- gtk2winapi.inc	(revision 59976)
+++ gtk2winapi.inc	(working copy)
@@ -432,7 +432,7 @@
     Result:=true;
   finally
     if SupportedFormats<>nil then FreeMem(SupportedFormats);
-    if SelData.Data<>nil then FreeMem(SelData.Data);
+    if (SelData.Data<>nil) and (PGdkAtom(SelData.Data)<>SupportedFormats) then FreeMem(SelData.Data);
   end;
 end;
 
patch.diff (450 bytes)

engkin

2019-01-02 20:33

reporter  

ShowClipboard.zip (129,792 bytes)

Juha Manninen

2019-01-12 21:27

developer   ~0113363

Applied, thanks.

Issue History

Date Modified Username Field Change
2019-01-02 20:32 engkin New Issue
2019-01-02 20:32 engkin File Added: patch.diff
2019-01-02 20:33 engkin File Added: ShowClipboard.zip
2019-01-12 21:27 Juha Manninen Fixed in Revision => r60064
2019-01-12 21:27 Juha Manninen LazTarget => -
2019-01-12 21:27 Juha Manninen Note Added: 0113363
2019-01-12 21:27 Juha Manninen Status new => resolved
2019-01-12 21:27 Juha Manninen Resolution open => fixed
2019-01-12 21:27 Juha Manninen Assigned To => Juha Manninen