As ATK has referenced, you'll need to make sure m_buffer is set to NULL after it's deleted at ln200 and after it's passed to the ThumbnailWriter a bit further down.