properly release msg at the end of reading to not leak.