fix use-after-free in earlier patch
Inadvertently added a use-after-free due to incomplete work in commit b0220259.
Reworked more substantially to deal with two cases in cgi_server_name():
- getenv() returning pre-allocated pointers to environment
- uname() requiring a memory allocation
Changed the method of returning the value so that a non-NULL value is a pointer to a heap allocation the caller must free after using it.
Also made sure time.h is included in the header file to quiet declaration warnings.