fix memory leaks in pkey.c