Recent

Author Topic: [SOLVED] Strange freezing problem  (Read 7006 times)

Maciej Kaczkowski

  • New Member
  • *
  • Posts: 31
    • Password Recovery Software
[SOLVED] Strange freezing problem
« on: April 08, 2013, 08:52:45 pm »
Hi,

After a year I still can't solve this problem:
http://lazarus.freepascal.org/index.php/topic,16567.msg90217.html

(1) When I run application without IDE, there is random freezing (sometimes works perfectly, in most cases its freeze i other close app without any information). (2) When its running with debugger, program stop at DbgUiConnectToDbg procedure. I've check all procedures serveral times, make code much safer, there is no memory leak at the end - and I have no idea what is wrong.

Here is video of case 1 and 2:
http://keit.co/p/wp-content/plugins/download-monitor/download.php?id=8

How can I find a solution to this problem?

Best regards
Maciej
« Last Edit: April 10, 2013, 07:41:32 am by Maciej Kaczkowski »

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 681
Re: Strange freezing problem
« Reply #1 on: April 08, 2013, 10:48:04 pm »
Can you tell us what operating system you're using?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11829
  • Debugger - SynEdit - and more
    • wiki
Re: Strange freezing problem
« Reply #2 on: April 08, 2013, 10:58:43 pm »
Sample code? How to reproduce?

"no memory leak" is no guarantee for correctness...

Anyway, nothing from any of your posts rings a bell for me. I got a gut feeling, you may access memory that was previously freed. (If you will, kind of the opposite of a leak). But that is as good a guess, as the numbers I play in lottery.

One way to go after accessing freed memory (in case that is a possibility), is tor compile the app on linux, and run under valgrind (there is none for windows)

--
Also if it freezes outside the IDE, Lazarus (svn trunk / 1.1) now has an "attach" feature, so you can see where the app crashed.
However likely this will not get you much more info, than running directly in the debugger.

Maciej Kaczkowski

  • New Member
  • *
  • Posts: 31
    • Password Recovery Software
Re: Strange freezing problem
« Reply #3 on: April 09, 2013, 09:27:22 am »
Can you tell us what operating system you're using?
Windows XP Pro SP3 - currently in VirtualBox (Linux) but the same is in normal OS (WinXP).

Quote
Sample code? How to reproduce?

I don't know how can I isolate invalid code.

Quote
Anyway, nothing from any of your posts rings a bell for me. I got a gut feeling, you may access memory that was previously freed. (If you will, kind of the opposite of a leak). But that is as good a guess, as the numbers I play in lottery.

All objects are freed correctly, I have only doubt when using ansistring something like a := 'b'; a[4] := 'c'; - its not called directly, always by using variable. Is there any possibility to detect situation when program access to character outside string?

Quote
One way to go after accessing freed memory (in case that is a possibility), is tor compile the app on linux, and run under valgrind (there is none for windows)
Currently its not possible because I use DPAPI, registry and protected storage. After serveral tests (finished today) I'm 99% sure that the problem is in part associated with the registry.

Best regards
Maciej

Quote
Also if it freezes outside the IDE, Lazarus (svn trunk / 1.1) now has an "attach" feature, so you can see where the app crashed.
However likely this will not get you much more info, than running directly in the debugger.
Thanks! I didn't know about this feature.
« Last Edit: April 09, 2013, 11:10:48 am by Maciej Kaczkowski »

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Strange freezing problem
« Reply #4 on: April 09, 2013, 11:11:00 am »
All objects are freed correctly, I have only doubt when using ansistring something like a := 'b'; a[4] := 'c'; - its not called directly, always by using variable. Is there any possibility to detect situation when program access to character outside string?
Well, there is 1 thing i'd almost call a bug, related to strings.
When you assign string2:=string1, their string data has same address. But after you change that data from one, the other is not changed.
Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
var s1, s2, s3: string;
begin
  s1:='String1';
  s2:=s1;
  s3:=s1;
  s3[7]:='3';
  caption:=format('%d %d %d (s1:%s) (s3:%s)',
    [integer(@s1[1]), integer(@s2[1]), integer(@s3[1]), s1, s3]);
end;
// At the end, s1 and s2 have same pointer, s3 differs. s1 and s3 print String1 String3

But doing something crazy like this:
Code: [Select]
s1:='String';
  s1:=s1+'1';
  s2:=s1;
  s3:=s1;
  PChar(@s3[7])^:='3';
Would print something else... Now s3 has same pointer as s1, and both s1 and s2 = String3.
« Last Edit: April 09, 2013, 11:18:53 am by User137 »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11829
  • Debugger - SynEdit - and more
    • wiki
Re: Strange freezing problem
« Reply #5 on: April 09, 2013, 04:13:50 pm »

Quote
Anyway, nothing from any of your posts rings a bell for me. I got a gut feeling, you may access memory that was previously freed. (If you will, kind of the opposite of a leak). But that is as good a guess, as the numbers I play in lottery.

All objects are freed correctly,
Does that include that no object is accessed after it has been freed. Such errors do happen.

Code: [Select]
a := TFoo.create;
b:= a;
....
// some place else
a.free;

// and yet another place, called later
b.Something

Quote
I have only doubt when using ansistring something like a := 'b'; a[4] := 'c'; - its not called directly, always by using variable. Is there any possibility to detect situation when program access to character outside string?

Only the range-check by the compiler -Cr

For testing you should have all of them enabled. -Criot -gh -gt
Also use -gtt and -gttt

If you got time (will run very slow), add:  -gp

http://www.freepascal.org/docs-html/user/usersu15.html#x38-450005.1.4

---
There is DrMemory. I have never tried it. No idea if it is of any use  http://www.drmemory.org/
http://www.chromium.org/developers/how-tos/using-drmemory

---

One thing to be aware of
Code: [Select]
procedure Foo(  CONST s: string);

do NOT use that ("var s: string" is fine). Because it requires your whole code to follow extra rules, or you will get into accessing the wrong memory.

Also check any calls to packages and LCL.

If you pass a string to something declared like this, copy it to a local variable (NOT object field, NOT global), and pass the local.
[object-field and global are ok, only if there is NO event that can be triggered while inside the call, or if such event does not access any such string)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Strange freezing problem
« Reply #6 on: April 09, 2013, 04:51:08 pm »
If you got time (will run very slow), add:  -gp

http://www.freepascal.org/docs-html/user/usersu15.html#x38-450005.1.4
Hi Martin: interesting tips!
Quote
-gp
    Preserve case in stabs symbol names. Default is to uppercase all names.
do you perhaps mean -pg?
Quote
-pg
Generate profiler code for gprof. This will define the symbol FPC_PROFILE, which can be used in conditional defines.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11829
  • Debugger - SynEdit - and more
    • wiki
Re: Strange freezing problem
« Reply #7 on: April 09, 2013, 05:09:39 pm »
Quote
-gp
    Preserve case in stabs symbol names. Default is to uppercase all names.
do you perhaps mean -pg?
Quote
-pg
Generate profiler code for gprof. This will define the symbol FPC_PROFILE, which can be used in conditional defines.

Sorry I meant

Quote from: fpc_doc
-gc
    Generate checks for pointers. This must be used with the -gh command line option. When this options is enabled, it will verify that all pointer accesses are within the heap.

And, well this can report false positives. If you get pointers from the OS, or a dll, then the heap-mgr would not know
« Last Edit: April 09, 2013, 05:11:40 pm by Martin_fr »

Maciej Kaczkowski

  • New Member
  • *
  • Posts: 31
    • Password Recovery Software
Re: Strange freezing problem
« Reply #8 on: April 09, 2013, 09:03:42 pm »
Thank you for all suggestions.
Last sentence was a solution: If you get pointers from the OS, or a dll, then the heap-mgr would not know

I rewrite all stuff based on advapi32, all CredEnumerate should be finished by CredFree. Tested about 30 minutes whitout freeze, so I think that will be fine. Based on:
http://blog.delphi-jedi.net/jedi-api-headers/

Thanks again :)

Best regards
Maciej

 

TinyPortal © 2005-2018