Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
posix/syslog: fix releasing ident string
The openlog() function stores the ident string in a userdata. Syslog stores a reference to this dynamically allocated string and uses it when printing log messages. When Lua exits closelog() is not automatically called causing syslog to keep the reference while the memory itself is freed. This caused segfaults when syslog was called from C code after Lua exited. A __gc metamethod was added to the ident field that automatically calls closelog(). If closelog() is called explicitly or openlog() is called for a second time the __gc metamethod is removed from ident to prevent closelog() from being called for a second time, possibly at a later point in time after openlog() has been called again.
- Loading branch information