Graceful exit

It's necessary to do serious checks for the memory leaks using
tools like valgrind. This patch tries to implement a graceful
exit for all tvheadend components and free allocated memory.

Also, some memory leaks were fixed.
Fixes for graceful exit patch

Mostly avahi related and cosmetic fixes for the graceful exit patch.
Fix the failure message in the global config when imagecache is not available.
Merge remote-tracking branch 'origin/pr/329'

Conflicts:
	src/tvheadend.h
Merge remote-tracking branch 'origin/pr/331'
Tmp Fix