merge_trees(): ensure that the callers release output buffer