fix NPE & leaked key