Fixed memory leak in resource writer