Correctly handle potential popen() failures

I believe the commit descriptions are sufficient here :)
I had a look through the code earlier today, relevant discussion can be found on Google+: https://plus.google.com/u/0/+IkeyDoherty/posts/i7KeTu5hnRv

Realise it was quite possible you wouldn't see the post, so here are the relevant fixes.

Something I believe that does need addressing also however is your use of splitting strings.with your
`str_replace` function. Please note that every time you call it, you have a newly allocated string returned
from the function which you need to free using `g_free()`.

Essentially, you have a whole bunch of strings being allocated and not freed. (Also look at your use of `g_strdup` *within* the method, that's two allocated and never-freed strings hanging around (The memory itself is never free'd)

If I have some time I might tackle this.

Hope this is somewhat helpful to you :)