Don't free here - rather have a block at the end of the function labeled 'cleanup' or 'failed' or 'done' which handles all cleanups generically, if needed initialized newhmr == NULL so that g_free can know if it was ever set.