Avoid memory leak when encoding the key
Merge remote-tracking branch: upstream/master