Fix some more compiler warnings.
Fix resource leak in create_pid_file().
Fix buffer overrun.
Explicitly return NULL or 0 on M_ABORT error.

This makes the work for static analyzing tools a lot easier that
don't understand that a M_ABORT means stop executing the program
and abort creating a crash on our way out.
Fix wrong return.
Use bstrncpy and not strncpy.
Don't return a pointer to a local variable.
Remove useless debug message.