[fpc-devel] Heaptrace + cwstring cause SIGSEGV at the end

2014-03-10 Thread Petr Kristan
Hi.

I use heaptrc and cwstring units in Linux.
If memoryleak occurs and program ends, then i get SIGSEGV in cwstring.pp:481 
(iconv call)
because cwstring unit is finalized before heaptrc.

#1 iconv(optimized out, 0x7fffd738, 0x7fffd760, 0x7fffd730, 
0x7fffd748) at iconv.c:53
#2 ANSI2WIDEMOVE(0x7fffef7cf038 '/home/petr/obis4/bin/obis-linux', 65001, 
0x7fffee687dd8 '', 31) at ../unix/cwstring.pp:481
#3 fpc_ansistr_to_widechararray(0x7fffd830 #43472#63484#32767, 255, 
0x7fffef7cf038 '/home/petr/obis4/bin/obis-linux') at ../inc/ustrings.inc:820
#4 ASSIGN({}, 0x7fffef7cf038 '/home/petr/obis4/bin/obis-linux') at 
../inc/file.inc:58
#5 ASSIGN({}, '/home/petr/obis4/bin/obis-linux') at ../inc/file.inc:71
#6 OPENEXEFILE({F = {}, SIZE = 0, ISOPEN = false, NSECTS = 0, SECHDROFS = 0, 
SECSTROFS = 0, PROCESSADDRESS = 0, FUNCTIONRELATIVE = false, IMGOFFSET = 0, 
FILENAME = ...
#7 OPENDWARF(0x4633a2) at ../inc/lnfodwrf.pp:152
#8 GETLINEINFO(4600738, '', '', 0) at ../inc/lnfodwrf.pp:734
#9 DWARFBACKTRACESTR(0x4633a2) at ../inc/lnfodwrf.pp:767
#10 CALL_STACK(0x7fffeea43d00, {}) at ../inc/heaptrc.pp:307
#11 DUMPHEAP at ../inc/heaptrc.pp:1233
#12 TRACEEXIT at ../inc/heaptrc.pp:1486
#13 HEAPTRC_$$_finalize at :1615
#14 FINALIZEUNITS at ../inc/system.inc:907
#15 INTERNALEXIT at ../inc/system.inc:960
#16 DO_EXIT at ../inc/system.inc:1024
#17 main at obis.lpr:63


Heaptrace is switched on by -gl fpc option.

obis.lpr:
uses
  cthreads, cwstring
...

fpc 2.7.1 and lazarus 1.3

Exists some solution for this problem?

Thanks
Petr

-- 
Petr Kristan
.
EPOS PRO s.r.o., Smilova 333, 530 02 Pardubice
tel: +420 461101401Czech Republic (Eastern Europe)
fax: +420 461101481
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Heaptrace + cwstring cause SIGSEGV at the end

2014-03-10 Thread Jonas Maebe


On 10 Mar 2014, at 16:13, Petr Kristan wrote:

If memoryleak occurs and program ends, then i get SIGSEGV in  
cwstring.pp:481 (iconv call)

because cwstring unit is finalized before heaptrc.



If you use -gh, then heaptrc will be the first unit of the uses clause  
and will be finalized after any manually added unit.



Heaptrace is switched on by -gl fpc option.


-gl switches on lineinfo, not heaptrc.


Jonas
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Heaptrace + cwstring cause SIGSEGV at the end

2014-03-10 Thread Sergei Gorelkin

10.03.2014 19:40, Jonas Maebe пишет:


On 10 Mar 2014, at 16:13, Petr Kristan wrote:


If memoryleak occurs and program ends, then i get SIGSEGV in cwstring.pp:481 
(iconv call)
because cwstring unit is finalized before heaptrc.



If you use -gh, then heaptrc will be the first unit of the uses clause and will 
be finalized after
any manually added unit.

That's exactly the issue. Being finalized last, heaptrc must not do anything that depends on 
functionality from other units, except system, but it does due to recent Unicode-related changes 
(indirectly, see the stack trace).


Even further, in case of error RTL tries to print a backtrace right after finalizing all units (see 
InternalExit procedure in system.inc), which can lead to similar problems.


Regards,
Sergei
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Heaptrace + cwstring cause SIGSEGV at the end

2014-03-10 Thread Jonas Maebe

On 10 Mar 2014, at 17:17, Sergei Gorelkin wrote:

 10.03.2014 19:40, Jonas Maebe пишет:
 
 On 10 Mar 2014, at 16:13, Petr Kristan wrote:
 
 If memoryleak occurs and program ends, then i get SIGSEGV in 
 cwstring.pp:481 (iconv call)
 because cwstring unit is finalized before heaptrc.
 
 
 If you use -gh, then heaptrc will be the first unit of the uses clause and 
 will be finalized after
 any manually added unit.
 
 That's exactly the issue. Being finalized last, heaptrc must not do anything 
 that depends on functionality from other units, except system, but it does 
 due to recent Unicode-related changes (indirectly, see the stack trace).
 
 Even further, in case of error RTL tries to print a backtrace right after 
 finalizing all units (see InternalExit procedure in system.inc), which can 
 lead to similar problems.

You're right. We should probably reinstally the previous (default) widestring 
manager in the finalization section of cwstring).


Jonas
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel