Recent

Author Topic: Memory corrupted by 3rd party application.  (Read 417 times)

mika

  • Full Member
  • ***
  • Posts: 128
Memory corrupted by 3rd party application.
« on: October 15, 2025, 10:26:40 pm »
I have Linux text mode app that run other apps. Those apps have means and sometimes they corrupt memory of my app. How to mitigate this problem?

It took me year or so to come to conclusion that 3rd party app is at fault. I confirmed it by doing  check sum of memory to be prone to corruption before running 3rd party app and after.  It happens once a month or once a week.  So it took a while.

ccrause

  • Hero Member
  • *****
  • Posts: 1080
Re: Memory corrupted by 3rd party application.
« Reply #1 on: October 16, 2025, 07:24:03 am »
There are several ways to launch 3rd party programs from FPC, please show the relevant code you use to launch the 3rd party program.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12531
  • FPC developer.
Re: Memory corrupted by 3rd party application.
« Reply #2 on: October 16, 2025, 10:19:30 am »
Since it is Linux and not Dos or some other older OS, a launched app should have its own memory space.

So maybe it is not direct memory corruption, but some how state altering when  the called program leaves things in a different state than usual. E.g.

  • if crashing, leaves the terminal in raw state or so.
  • The code or component that executes mutates memory during the forking process. How do you execute?



« Last Edit: October 16, 2025, 10:22:10 am by marcov »

Thaddy

  • Hero Member
  • *****
  • Posts: 18330
  • Here stood a man who saw the Elbe and jumped it.
Re: Memory corrupted by 3rd party application.
« Reply #3 on: October 16, 2025, 11:43:23 am »
If you use Tprocess, make sure it does not inherit handles, the launched process should run detached.
Code: Pascal  [Select][+][-]
  1.   process.inherithandles := false;    // all platforms
  2.   process.options := [poDetached]; // has only effect on Windows?, otherwise empty.
Inheriting handles may cause leaks to propagate, afaik also on Linux.
When the process is launched detached your launching application will not be affected, but the process needs to be killed explicitly if so desired, because otherwise the launched process will keep running even if you close the launching app.
But any leaks will stay in the launched application....

Remark: output/input redirection [poUsePipes] will still work if you use that.
Remark 2: in your case this may be the last resort, because normally you would want to run it as a child process. But the above means your launching app is never affected memory wise.
« Last Edit: October 16, 2025, 12:05:09 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

mika

  • Full Member
  • ***
  • Posts: 128
Re: Memory corrupted by 3rd party application.
« Reply #4 on: October 16, 2025, 12:13:09 pm »
... please show the relevant code you use to launch the 3rd party program.

Code: Pascal  [Select][+][-]
  1. s:=fpsystem(Progname+' '+Comline);

 

TinyPortal © 2005-2018