<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<br>
<div class="moz-cite-prefix">Le 24/05/2013 11:37, Antonio Fortuny a
écrit :<br>
</div>
<blockquote cite="mid:knncd4$uii$1@ger.gmane.org" type="cite">
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<font face="Helvetica, Arial, sans-serif">Hi Folks.<br>
<br>
I'have already submitted this boring problem to the Indy's team
on <a moz-do-not-send="true"
href="http://forums2.atozed.com/viewtopic.php?f=7&t=26492&p=32031#p32031">http://forums2.atozed.com/viewtopic.php?f=7&t=26492&p=32031#p32031</a>.<br>
Because FPC or Lazarus could be involved, I post it here as
well.<br>
The first post on Indy's forum is not too long and explains the
problem so it will be enough I suppose. Anyway if you need some
more iformation about either the problem itself or Indy, please
ask me. You could also post answers into the Indy's forum as
well.<br>
<br>
Thanks,<br>
<br>
Antonio.</font><br>
</blockquote>
<font face="Helvetica, Arial, sans-serif">Hoping to get more
information to fix the problem, I added the heaptrc unit to the
project. Bad luck, all I get is the attached file.<br>
Only two lines are pertinent for my program, all the rest is
untrackable.<br>
Worse, when I trace the program, I get something abnormal. The
query solver procedure is entered as an incoming TCP/IP requests
it, The DB is accessed by the means of a query liked to a
transaction. The query is opened and a dynamically allocated
buffer is built, out of column definitions and data rows. After
having copied the field definitions in the main buffer, when the
work buffer is nil'ed (ReallocMem to 0) control returns to very
first line of the procedure as if the CPU turns to be crazy. All
memory buffers and variables look OK until this point. Code
snippet:<br>
<br>
</font><tt>function TConnection.ExecQuery(const Sql: String; out
PData: PChar; out DataLen: Integer; out Msg: String): Boolean;</tt><tt><br>
</tt><tt>var</tt><tt><br>
</tt><tt>...</tt><tt><br>
</tt><tt>begin</tt><tt><br>
</tt><tt>...</tt><tt><br>
</tt><tt> try</tt><tt><br>
</tt><tt> try</tt><tt><br>
</tt><tt> try</tt><tt><br>
</tt><tt> FQ.Sql.Text := Sql;</tt><tt> <<<=========================================+</tt><tt><br>
</tt><tt>
...
|<br>
</tt><tt> PData :=
nil; |</tt><tt><br>
</tt><tt> ReAllocMem(PData, wFullSize +
1); |</tt><tt><br>
</tt><tt> DataPos :=
0; |</tt><tt><br>
</tt><tt> Move(PChar(wHeader)^, (PData + DataPos)^,
HeaderLen); |</tt><tt><br>
</tt><tt> Inc(DataPos,
HeaderLen); |</tt><tt><br>
</tt><tt> Move(PFields^, (PData + DataPos)^,
FldPos); |</tt><tt><br>
</tt><tt> Inc(DataPos,
FldPos); |</tt><tt><br>
</tt><tt> ReAllocMem(PFields, 0); <========== BOOM
control goes back to =======</tt><tt>+</tt><tt><br>
</tt><tt> (PData + DataPos)^ := #0;</tt><tt><br>
</tt><font face="Helvetica, Arial, sans-serif"><br>
When I remove heaptrc, everything returns back to normal, except
the main error of course.<br>
The program uses SqlDB with a Firebird database in a thread
context. But for he time being, only one thread is actually
accessing the DB. On the other hand, every incoming TCP/IP
connection, serviced by an Indy thread, owns a database connection
until the connection is closed. This means that DB connections
should be thread safe. I achieved this by using a DB connections
list protected by a crittical section to add or reuse a DB
connection from the list. I'm pretty sure that this architecture
looks thread safe.<br>
Do not forget that the same code runs on Win64 and Linux x86_64<br>
This time I thing I'll become crazy too. <span
class="moz-smiley-s12"><span> :-$ </span></span><br>
I'll take a relaxing WE and come back on monday.<br>
<br>
Antonio.<br>
</font>
</body>
</html>