fixed memory leak in SetKey() and a warning