Cut some resource leaks in instrumenting process