Use g_realloc instead of realloc

Since g_malloc is used for allocation, the application is terminated if a call
to allocate memory fails. Therefore the typical realloc error that existed,
which will overwrite the pointer with NULL without freeing the previous
allocated memory can be replaced by a simple call to g_realloc.
Only use glib memory allocation functions in lib/rsa .c

Since all the other functions in lib/rsa.c are using the glib memory
allocation functions, we do the same in public_key_to_gstring and
public_key_append_to_gstring to avoid the typical realloc error that exists,
which will overwrite the pointer with NULL without freeing the previous
allocated memory. Since there exists no proper error handling and the other
functions are using the glib functions, this patch replaces the memory
allocation functions of stdlib with those of glib.
Resolve pidfile resource leaks

This patch resolves resource leaks caused by not closing the file streams upon
an write error.
Use glib allocation functions in lib/utils.c

Since other function in lib/utils.c are using glib functions for memory
allocations and return their pointers (which then have to be freed accordingly
with g_free), we do the same for strsplit_by_space and strsplit_by_char. In
addition g_realloc is used instead of realloc since no proper error handling is
done if the realloc call fails. Therefore previously allocated memory would be
leaked. Since almost any other function uses glib memory allocation functions
will make the application terminate upon an memory error, we can assume to use
glib functions here as well.