+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Senior Member Snify's Avatar
    Join Date
    May 2009
    Location
    Syla's Heart <3
    Posts
    270

    [NEED HELP] Memory Leak GETIPFROMHOST

    Hi Guys,

    I have this code right here to retrive the IP-address from a hostname:

    Code:
    program Project1;
    
    {$APPTYPE CONSOLE}
    
    uses
      SysUtils,
      winsock;
    
    function GetIPFromHost(const HostName: string): string;
    type
      TaPInAddr = array[0..10] of PInAddr;
      PaPInAddr = ^TaPInAddr;
    var
      phe: PHostEnt;
      pptr: PaPInAddr;
      i: Integer;
    begin
      Result := '';
      phe := GetHostByName(PChar(HostName));
      if phe = nil then Exit;
      pPtr := PaPInAddr(phe^.h_addr_list);
      i := 0;
      while pPtr^[i] <> nil do
      begin
        Result := inet_ntoa(pptr^[i]^);
        Inc(i);
      end;
    end;
    
    var
    wsaData: TWSAData;
    
    begin
    
    if (WSAStartup($0202, wsaData) <> 0) then begin
          Exit;
    end;
    
    while true do begin
    sleep (1000);
    GetIPFromHost ('localhost');
    end;
    it works fine and gives me the IP address.
    Unfort. I need this function a couple of times to compare a DNS with an IP-address.

    For some reason I get a big Memory Leak and the memory of my program increases very fast.
    Why is that and how can I free the memory?

    Thanks in advance.
    There are only 10 types of people - those, who understand binary, and those, who don't.
    Pytho Remote Administration Tool

  2. #2
    Senior Member cypherk's Avatar
    Join Date
    Nov 2010
    Location
    Brazil
    Posts
    248
    Delphi must have some sort of free or flush argument for objects. If so, just do it at the end of each usage. Should help imo
    _|_

  3. #3
    Senior Member Snify's Avatar
    Join Date
    May 2009
    Location
    Syla's Heart <3
    Posts
    270
    I tried FreeandNil I tried phe:= NIL; and I tried freemem. All these make the whole program crash :/
    There are only 10 types of people - those, who understand binary, and those, who don't.
    Pytho Remote Administration Tool

  4. #4
    Member H1N1's Avatar
    Join Date
    Jun 2010
    Posts
    76
    You could try this, http://www.eurekalog.com/downloads_delphi.php

    You can have it report exceptions on memory leaks or check out this : http://stackoverflow.com/questions/6...nder-delphi-xe

  5. #5
    Senior Member
    Join Date
    Jun 2008
    Location
    0x40000
    Posts
    1,523
    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. Therefore, the data should be copied before another Windows Sockets call is made.
    Source: MSDN.

    Most likely that function allocates memory. You could shutdown WSA and see if the memory is freed. Same applies for GetHostByName.

    GetHostByName(PChar(HostName));
    Here you convert the string to a pChar, without freeing the memory. Probably that pChar isn't freed by delphi.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Herpes Net 1.5.2 (not a leak)
    By NoNh in forum Cracked Malware
    Replies: 43
    Last Post: 10-01-2012, 17:02
  2. Sub7 2.3.1 (MM) Leak new
    By x0xh in forum Malware Samples and Information
    Replies: 19
    Last Post: 11-03-2011, 05:42
  3. Windows 8 alpha leak?
    By D92 in forum Off-Topic
    Replies: 3
    Last Post: 10-03-2011, 08:21
  4. [LEAK]Wormy Spreader 3.1
    By basjuh in forum Malware Samples and Information
    Replies: 75
    Last Post: 02-06-2010, 23:53
  5. [REQ]Leak test
    By slayer616 in forum General Programming Help
    Replies: 3
    Last Post: 07-02-2009, 20:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.