Avatar of shawn857
shawn857

asked on 

Getting error: "FastMM has detected a FreeMem call after FastMM was uninstalled"

Hi, I'm using FastMM4 in my project and during runtime, it throws off this error:

"FastMM has detected a FreeMem call after FastMM was uninstalled"

I don't use any "Freemem" calls in my code, but I do a "Dispose" in one of my functions which gets called repeatedly from within a loop:

function PhoneNumMask(const Str: string; const hmask: string): PChar;
var
  Pstr, Pmask, ResultStr: PChar;
begin
  Pstr := PChar(Str);
  Pmask := PChar(hmask);
  New(ResultStr);

  while Pmask^ <> #0 do
  begin
    if Pmask^ <> '#' then   // a literal character in the mask, output it directly
       StrCat(ResultStr,PChar(string(Pmask^)))
    else  // output a digit
    begin
      while (PStr^ <> #0) and not (PStr^ in ['0'..'9']) do
        Inc(PStr);
      if PStr^ = #0 then BREAK;  // Exit loop

      StrCat(ResultStr,PChar(string(PStr^)));   // Tack on a digit to the result string
      Inc(PStr);
    end;

    Inc(Pmask);
  end; // while Pmask^ <> #0 do

  Result:=ResultStr;
  Dispose(ResultStr);
end;  // PhoneNumMask

Open in new window


... I prepare a new PChar variable "ResultStr" with the NEW command, then do a DISPOSE of it at the end. I can't see the problem. My app processes text files on disk and I ran a test on a 20 meg file and it went about 5% though the data, and only then gave the error. So the error didn't happen immediately... it took a lot of iterations before it happened.
   Maybe I don't even *need* variable "ResultStr" and I can just assign my function's result to the default "Result"....

Thanks
    Shawn
Delphi

Avatar of undefined
Last Comment
shawn857

8/22/2022 - Mon