getHTTPFile and memory leaks lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- IPguy · 2011-07-19 01:51 The below code works as long as I comment out the s.Free line in the function, but I have 3 unfreed memory blocks. When it works, I receive the desired simple string from my web server. When I enable the s.Free line, I get a SIGSEGV. And I think I should create and free the variable VerFromServer  in the calling procedure, but when I add the the create / free, I also get a SIGSEGV. Any thoughts / suggestions / RTFM links?  (ah, that would be "Read the FINE manual!"  grin) note: I'm not attempting to do a httpS transaction. Code: [Select]Function GetHTTPfile(const url: string) : tstringlist; // gets a file from the named url and returns the file contents // I'm using this to get the current version of the application from the web server var   s : tstringlist;   gotResponse : Boolean; begin   s := tstringlist.create;   gotResponse := HttpGetText(url,s);   // showmessage(s.text);   if gotResponse = true     then GetHTTPFile := s;   // s.Free; end;  // of GetHTTPfile                                           Procedure CheckforPgmUpdate(); var   VerFromServer : tStringList;   VerServer     : String; begin   VerFromServer :=   GetHTTPfile(VerFile);  // VerFile is a string containing the desired URL...   VerServer := VerFromServer[0];   If VerFromServer[0] > ver1  // ie: a newer version is available ...     then ShowMessage('A newer version of the progarm is available.'                         + SLineBreak + 'Visit the web site to download it.'); end;  // for CheckforPgmUpdate ---------------------------------------------------------------------- IPguy · 2011-07-19 02:01 http://www.lazarus.freepascal.org/index.php/topic,10551.msg52415.html# msg52415 Looks like Indy might exhibit the same/similar memory leak, based on the comment in Sept 2010. ---------------------------------------------------------------------- IPguy · 2011-07-22 02:17 Bump.  Any thoughts? ---------------------------------------------------------------------- Ocye · 2011-07-26 14:48 Don't mix local and referenced variables. You assign the function's result to a TStringlist that is created (and freed) within the function itself. To solve the problem, submit a valid object. Code: [Select]Function GetHTTPfile(const url: string) : TStrings; begin   HttpGetText(url,Result);   //it makes no sense to put the call in a separet function end; Procedure CheckforPgmUpdate(); var   VerFromServer : TStringList; begin   VerFromServer:=TStringList.Create;   try     VerFromServer :=   GetHTTPfile(VerFile);     if VerFromServer.Count>0 then...   finally     VerFromServer.Free;   end; end; If the method HttpGetText() is defined as HttpGetText(const aUrl:string; out/var aText:string) you should not use a TStringList. ---------------------------------------------------------------------- IPguy · 2011-07-27 03:19 Ocye, Thanks for the help.  That solved my issues. I have a few places that I check for the version and I was attempting to create a common routine that could be called from a few locations - hence the separation of the function and the procedure. HttpGetText is part of the Ararat Synapse code and is defined as shown below: function HttpGetText(const URL: string; const Response: TStrings): Boolean;