[fix] added buffer memory cleaning in case of failure