May be you are right, here is another version of the function that i found.
In my software is called only one time, i didn't mind about the leak, thank
you.

Best regards


Function GetIPAddress():String;
type
  pu_long = ^u_long;
var
  varTWSAData : TWSAData;
  varPHostEnt : PHostEnt;
  varTInAddr : TInAddr;
  namebuf : Array[0..255] of char;
begin
  If WSAStartup($101,varTWSAData) <> 0 Then
    Result := ''
  Else
  begin
    gethostname(namebuf,sizeof(namebuf));
    varPHostEnt := gethostbyname(namebuf);
    varTInAddr.S_addr := u_long(pu_long(varPHostEnt^.h_addr_list^)^);
    Result := ''+inet_ntoa(varTInAddr);
  End;
  WSACleanup;
end;


2009/8/30 Markku Uttula <markku.utt...@disconova.com>

> Alejandro Casagrande wrote:
> >     WSAStartup($101, GInitData);
> >     Result := '';
> >     GetHostName(Buffer, SizeOf(Buffer));
> >     phe :=GetHostByName(buffer);
> >     if phe = nil then Exit;
> >     pptr := PaPInAddr(Phe^.h_addr_list);
> >     i := 0;
> >     while pptr^[i] <> nil do
> >     begin
> >       result:=StrPas(inet_ntoa(pptr^[i]^));
> >       Inc(i);
> >     end;
> >     WSACleanup;
>
> Hmm... doesn't this leak memory in the case that GetHostByName returns
> nil (because WSACleanup never gets called because the exit-command).
>
> --
> Markku Uttula
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> synalist-public mailing list
> synalist-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/synalist-public
>



-- 
Ing. Alejandro Casagrande
Advenio Software
http://www.advenio.com.ar
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
synalist-public mailing list
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to