View Issue Details

IDProjectCategoryView StatusLast Update
0025458LazarusLCLpublic2014-01-06 18:41
ReporteraccSoneAssigned ToPaul Ishenin 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformdarwin x86_64OSOSXOS Version10.6.8
Product Version1.3 (SVN)Product Build 
Target Version1.3 (SVN)Fixed in Version1.4 
Summary0025458: Memory leak on empty strings in function TWidgetSet.DrawText (fix attached)
DescriptionDue to BP compatibility there is a double termination on zero count empty strings that will lead to memory leaks.
Steps To ReproduceCall function with Str count=0 together with heaptrc (-gh) option on. heaptrc will throw error and halt later.
Additional Informationsee fix attached
TagsNo tags attached.
Fixed in Revision43648
LazTarget-
WidgetsetCocoa
Attached Files
  • fix_0025458.patch (646 bytes)
    Index: /Developer/lazarus_trunc/lcl/include/intfbasewinapi.inc
    ===================================================================
    --- /Developer/lazarus_trunc/lcl/include/intfbasewinapi.inc	(revision 43456)
    +++ /Developer/lazarus_trunc/lcl/include/intfbasewinapi.inc	(working copy)
    @@ -636,7 +636,10 @@
         Count := StrLen(Str);
     
       {Calculate # Lines, etc.}
    -  pStr := StrAlloc(Count + 1);
    +  if Str[0] = #0 then
    +    pStr := StrAlloc(2)  // because below StrLCopy will do a double 0 termination to be compatible with BP in this case
    +    else
    +    pStr := StrAlloc(Count + 1);
       try
         StrLCopy(pStr, Str, Count);
         pStr[Count] := #0;
    
    fix_0025458.patch (646 bytes)

Activities

accSone

2013-12-25 21:21

developer  

fix_0025458.patch (646 bytes)
Index: /Developer/lazarus_trunc/lcl/include/intfbasewinapi.inc
===================================================================
--- /Developer/lazarus_trunc/lcl/include/intfbasewinapi.inc	(revision 43456)
+++ /Developer/lazarus_trunc/lcl/include/intfbasewinapi.inc	(working copy)
@@ -636,7 +636,10 @@
     Count := StrLen(Str);
 
   {Calculate # Lines, etc.}
-  pStr := StrAlloc(Count + 1);
+  if Str[0] = #0 then
+    pStr := StrAlloc(2)  // because below StrLCopy will do a double 0 termination to be compatible with BP in this case
+    else
+    pStr := StrAlloc(Count + 1);
   try
     StrLCopy(pStr, Str, Count);
     pStr[Count] := #0;
fix_0025458.patch (646 bytes)

Paul Ishenin

2014-01-05 12:17

manager   ~0072219

I don't see where the code expects double termination but probably r43648 fixes the problem.

accSone

2014-01-06 18:41

developer   ~0072261

Pauls latest changes fixed issue. Thanks!

Issue History

Date Modified Username Field Change
2013-12-25 21:20 accSone New Issue
2013-12-25 21:20 accSone Status new => assigned
2013-12-25 21:20 accSone Assigned To => Paul Ishenin
2013-12-25 21:21 accSone File Added: fix_0025458.patch
2014-01-05 12:17 Paul Ishenin Fixed in Revision => 43648
2014-01-05 12:17 Paul Ishenin Note Added: 0072219
2014-01-05 12:17 Paul Ishenin Status assigned => resolved
2014-01-05 12:17 Paul Ishenin Fixed in Version => 1.4
2014-01-05 12:17 Paul Ishenin Resolution open => fixed
2014-01-06 18:41 accSone Note Added: 0072261
2014-01-06 18:41 accSone Status resolved => closed