Fixing some leaks and performance.

Uses some glib defines toSupport older glib versions.
Merge pull request #93 from awsaba/more_leak_fixes

Fixing some leaks and performance.