fix: some glitches here and there

 - memleak in case realloc() fails
 - g_strndup() memory must be freed with g_free()
 - some minor memleaks
 - check the return value of strdup-like functions
Merge pull request #12 from pozdnychev/master

Minor bugfixes after a quick review