Fix a few memory leaks

Detected by Cppcheck

These fixes is not in eog yet, I need to register on  GNOME bugzilla to send them.
No need to allocate str so early, see https://github.com/monsta/eom/commit/07939cf90a7eb3fccbfb5d4ff48c8204ec4dc766#diff-1