Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This code does not leak. Either your leak detection is faulty, or the code you are actually running is more complex than this and the leak is in the code that you have not shown.</p> <p>The only memory allocated by the Delphi RTL, in the code in the question, is for the dynamic strings. Delphi dynamic string handling does not leak. The calls to WinSock, <code>gethostbyname</code> and <code>inet_ntoa</code> allocate memory internal to WinSock.</p> <p>In the case of <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms738524.aspx" rel="nofollow"><code>gethostbyname</code></a>:</p> <blockquote> <p>The memory for the hostent structure returned by the gethostbyname function is allocated internally by the Winsock DLL from thread local storage. Only a single hostent structure is allocated and used, no matter how many times the gethostbyaddr or gethostbyname functions are called on the thread. The returned hostent structure must be copied to an application buffer if additional calls are to be made to the gethostbyname or gethostbyaddr functions on the same thread. Otherwise, the return value will be overwritten by subsequent gethostbyname or gethostbyaddr calls on the same thread. The internal memory allocated for the returned hostent structure is released by the Winsock DLL when the thread exits.</p> </blockquote> <p>And likewise for <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms738564.aspx" rel="nofollow"><code>inet_ntoa</code></a>:</p> <blockquote> <p>The string returned by inet_ntoa resides in memory that is allocated by Windows Sockets. The application should not make any assumptions about the way in which the memory is allocated. The string returned is guaranteed to be valid only until the next Windows Sockets function call is made within the same thread.</p> </blockquote> <p>Whilst it is true that the code in the question does not call <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms741549.aspx" rel="nofollow"><code>WSACleanup</code></a> that's fine since it is rather pointless to reclaim resources at process termination time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload