Fix various leaks found by coverity
(cherry picked from commit 69d87836c022153f48ff5d332e2021fe4cf8d8b0)

Conflicts:
	src/develop/masks/group.c
	src/develop/masks/masks.c
	src/imageio/format/j2k.c

These files aren't in 1.1.x to begin with :)