Automator workflow to close programme when laptop is closed / goes to sleep
Yes, this is possible. There are restrictions to performing scripts before sleep but it is possible.

Run a script on sleep

See Possible to run scripts on sleep and wake? for various tools that can run a script before sleep. I wrote, and thus recommend, Power Manager.

For the script, consider using AppleScript instead of Automator. Running an AppleScript before sleep will be simpler. The script could read:

tell application "MemoryLeak.app" to quit